Cod sursa(job #2076447)
| Utilizator | Data | 26 noiembrie 2017 16:47:54 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int ap[1000000];
int main()
{
int n, a[100000], maxx = 0, ok = 0, c = 0;
f>>n;
for(int i=1;i<=n;i++){
f>>a[i];
ap[a[i]]++;
if( a[i] > maxx ){
maxx = a[i];
}
}
for(int i=1;i<= maxx && ok == 0; i++){
if(ap[i] == n/2+1){
g<<i<<" "<<ap[i];
ok = 1;
c = 1;
}
}
if( c == 0)
g<<-1;
return 0;
}
