Cod sursa(job #1472034)
Utilizator | Data | 15 august 2015 23:05:55 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Teme Pregatire ACM Unibuc 2013 | Marime | 0.39 kb |
#include <fstream>
#define N 1000001
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int poz[N];
int n, i, maj, x;
int main ()
{
f >> n;
for (i=0; i<n; i++)
{
f >> x;
poz[x]++;
if (poz[x] > poz[maj])
maj = x;
}
if (poz[maj] >= n/2+1)
g << maj << " " << poz[maj];
else
g << -1;
return 0;
}