Cod sursa(job #663971)
Utilizator | Data | 19 ianuarie 2012 12:59:53 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.31 kb |
#include <fstream>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int max1,n,i,x,a[1000001],poz;
int main ()
{
f>>n;
max1=0;
for (i=1;i<=n;i++)
{
f>>x;
a[x]++;
if (a[x]>max1) {max1=a[x]; poz=x;}
}
if (max1>=n/2+1)
g<<poz<<' '<<max1<<'\n';
else g<<"-1\n";
return 0;
}