Cod sursa(job #1608333)
| Utilizator | Data | 21 februarie 2016 23:46:46 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
#include <map>
using namespace std;
map<long long,long long> x;
ifstream cin("elmaj.in");
ofstream cout("elmaj.out");
int n,aux,i;
int main()
{
cin>>n;
for(i=1;i<=n;i++){
cin>>aux;
x[aux]++;
}
for(map<long long,long long>::iterator it=x.begin();it!=x.end();++it)
if(it->second>=n/2+1){
cout<<it->first<<' '<<it->second;
return 0;
}
cout<<-1;
return 0;
}
