Cod sursa(job #1971923)
Utilizator | Data | 21 aprilie 2017 11:54:08 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int n, i, ap[1000001];
long x, maj;
int main()
{
fin >> n;
for(i=1; i<=n; i++)
{
fin >> x;
ap[x]++;
if(ap[x] > ap[maj])
maj = x;
}
if(ap[maj] > n/2)
fout << maj << " " << ap[maj];
else
fout << -1;
fin.close();
return 0;
}