Cod sursa(job #887744)
Utilizator | Data | 24 februarie 2013 04:20:57 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include<fstream>
using namespace std;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
int v[1000010];
int main()
{
int i, j, n, max=0, e;
in >> n;
for(i=1;i<=n;i++)
{
in >> j;
v[j]++;
if(v[j]>max)
{
max=v[j];
e=j;
}
}
if(max>=n/2+1)
out << e << " " << max;
else
out << "-1";
in.close();
out.close();
return 0;
}