Cod sursa(job #1690465)
Utilizator | Data | 15 aprilie 2016 09:13:13 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int N,x,k;
unordered_map<int,int> M;
int main()
{
ios_base::sync_with_stdio(0);
fin.tie(0);
fin>>N;
for(int i=0; i<N; ++i)
{
fin>>x;
M[x]++;
if(M[x]>N/2)k=x;
}
if(k)fout<<k<<" "<<M[k];
else fout<<"-1";
return 0;
}