Cod sursa(job #1477534)
| Utilizator | Data | 26 august 2015 15:07:24 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
// Galatan Tudor - Liceul Teoretic "Ion Luca"
// Vatra Dornei, 26.08.2015
#include <fstream>
#define R 1000001
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int nr_ap[R];
int n, i, x, el_maj;
int main ()
{
f >> n;
for (i=0; i<n; i++)
{
f >> x;
nr_ap[x]++;
if (nr_ap[x] > nr_ap[el_maj])
el_maj = x;
}
if (nr_ap[el_maj] >= n/2+1)
g << el_maj << " " << nr_ap[el_maj];
else
g << "-1";
return 0;
}