Cod sursa(job #1790089)
| Utilizator | Data | 27 octombrie 2016 19:45:21 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <fstream>
using namespace std;
#define in "elmaj.in"
#define out "elmaj.out"
const int N=1000001;
int n, f[N], sol;
int main() {
ifstream fin;
fin.open(in);
fin >> n;
for (int i = 0; i < n; i++) {
int x;
fin >> x;
f[x]++;
if (f[x] > f[sol])
sol = x;
}
fin.close();
ofstream fout;
fout.open(out);
if (f[sol] > n/2 + 1)
fout << sol << " " << f[sol];
else
fout << -1;
fout.close();
return 0;
}
