Cod sursa(job #2372155)
Utilizator | Data | 6 martie 2019 22:00:32 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int n, x, maj, ap[1000005];
int main()
{
fin >> n;
for(int i=1; i<=n; i++)
{
fin >> x;
ap[x]++;
if(ap[x]>ap[maj])
maj=x;
}
if(ap[maj]>n/2)
fout << maj << ' ' << ap[maj];
else
fout << -1;
return 0;
}