Cod sursa(job #797460)
| Utilizator | Data | 14 octombrie 2012 02:47:02 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <stdio.h>
#include <ext/hash_map>
#include <fstream>
#include <string>
#define NMAX 1000005
#define LMAX 12
using namespace std;
using namespace __gnu_cxx;
int n,A[NMAX],rez;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
hash_map <int,int> H;
int main()
{
in>>n;
int i,x;
for (i=1; i<=n; i++)
{
in>>x; H[x]++;
if (H[x]>=n/2+1)
rez=x;
}
if (rez)
printf("%d %d\n",rez,H[rez]);
else
printf("-1\n");
return 0;
}
