Cod sursa(job #1991906)
Utilizator | Data | 18 iunie 2017 17:19:15 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
#include <unordered_map>
#include <vector>
using namespace std;
ifstream cin("elmaj.in");
ofstream cout("elmaj.out");
int main(){
int n;
cin >> n;
vector<int> v(n + 1);
unordered_map<int, int> h;
for(int i = 1; i <= n; i++){
cin >> v[i];
h[v[i]] += 1;
}
int Max = -1;
for(int i = 1; i <= n; i++){
if(h[v[i]] > h[Max]){
Max = v[i];
}
}
if(h[Max] >= n / 2 + 1)
cout << Max << ' ' << h[Max] << '\n';
else
cout << "-1" << '\n';
}