Cod sursa(job #1886906)
Utilizator | Data | 21 februarie 2017 11:18:27 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include<fstream>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int ap[1000001],n,i,x,M,ok,p;
int main ()
{
f>>n;
for(i=1;i<=n;i++)
{
f>>x;
if(x>M)
M=x;
ap[x]++;
}
for(i=1;i<=M&&!ok;i++)
{
if(ap[x]==n/2+1)
{
p=x;
ok=1;
}
}
if(ok==1)
g<<p<<" "<<ap[p];
else
g<<-1;
return 0;
}