Cod sursa(job #3251613)
Utilizator | Data | 26 octombrie 2024 11:47:38 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int n, x;
unordered_map<int, int> f;
int main()
{
fin>>n;
for(int i=1; i<=n; i++){
fin>>x;
f[x]++;
}
for(auto elem: f){
if(elem.second>n/2){
fout<<elem.first<<" "<<elem.second;
return 0;
}
}
fout<<-1;
return 0;
}