Cod sursa(job #1313615)
| Utilizator | Data | 10 ianuarie 2015 21:39:20 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <fstream>
#include <vector>
using namespace std;
#define MOD 666013
long long n,loc,i,maxim,el,x,nr,j;
vector <long> h[666015];
int main()
{
ifstream f("elmaj.in");
ofstream g("elmaj.out");
f>>n;
for (i=1;i<=n;++i) {
f>>x;
loc=x%MOD;
h[loc].push_back(x);
nr=0;
for (j=0;j<h[loc].size();++j)
if (h[loc][j]==x) ++nr;
if (nr>maxim) {maxim=nr;el=x;}
}
if (maxim>=n/2+1) g<<el<<' '<<maxim;
else
g<<"-1";
f.close();
g.close();
return 0;
}
