Cod sursa(job #2550084)
Utilizator | Data | 18 februarie 2020 13:08:10 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <bits/stdc++.h>
using namespace std;
int main()
{
ifstream cin("elmaj.in");
ofstream cout("elmaj.out");
unordered_map<int, int> um;
int n, x;
cin >> n;
while(cin >> x)
++um[x];
for(auto &c: um){
if(c.second >= n / 2 + 1){
cout << c.first << ' ' << c.second << '\n';
return 0;
}
}
cout << "-1\n";
}