Cod sursa(job #735306)
| Utilizator | Data | 16 aprilie 2012 00:25:20 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define nmax (int)1e6
long n,v[nmax];
int main()
{
freopen("elmaj.in","r",stdin);
freopen("elmaj.out","w",stdout);
long i;
scanf("%ld", &n);
for(i=0;i<n;i++) scanf("%ld", &v[i]);
sort(v,v+n);
long value=v[n/2];
if((upper_bound(v,v+n,value)-lower_bound(v,v+n,value))>=n/2+1)
{
printf("%ld %ld", value,(upper_bound(v,v+n,value)-lower_bound(v,v+n,value)));
}else
{
printf("-1");
}
return 0;
}
