Cod sursa(job #2195648)
| Utilizator | Data | 16 aprilie 2018 22:02:52 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <bits/stdc++.h>
using namespace std;
int n,x;
map<int,int>mp;
map<int,int>::iterator it;
int main()
{
freopen("elmaj.in","r",stdin);
freopen("elmaj.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
mp[x]++;
}
for(it=mp.begin();it!=mp.end();it++)
if(it->second>=n/2+1)
break;
if(it==mp.end())
printf("-1");
else
printf("%d %d",it->first,it->second);
return 0;
}
