Cod sursa(job #1461252)
| Utilizator | Data | 15 iulie 2015 11:17:22 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int main(){
int n, v[1000000], x, max=0, i;
fin >> n;
while(fin>>x){
v[x]++;
if(max < v[x]){
max = v[x];
i = x;
}
}
if(max <= n/2){
fout << -1;
return 0;
}
fout << i << " " << max;
return 0;
}
