Cod sursa(job #1755157)
| Utilizator | Data | 9 septembrie 2016 15:09:16 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.4 kb |
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
map<int,int> a;
int n,maxv,maxc=-1;
int main(){
freopen("elmaj.in", "r", stdin);
freopen("elmaj.out", "w", stdout);
int e,x;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&x);
a[x]++;
if(a[x]>maxc){maxc=a[x];maxv=x;}
}
if(maxc>=n/2)
printf("%d %d",maxv,maxc);
else printf("-1");
}
