Cod sursa(job #2727131)
Utilizator | Data | 21 martie 2021 14:48:02 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Teme Pregatire ACM Unibuc 2013 | Marime | 0.41 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
unordered_map<int, int> ump;
int main() {
int n;
f >> n;
for(int i = 1; i <= n; i++) {
int x;
f >> x;
ump[x]++;
}
for(auto it : ump) {
if(it.second > n / 2) {
g << it.first << ' ' << it.second;
return 0;
}
}
g << -1;
return 0;
}