Cod sursa(job #2282460)

Utilizator AlexPascu007Pascu Ionut Alexandru AlexPascu007 Data 13 noiembrie 2018 19:39:38
Problema Elementul majoritar Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.35 kb
#include <fstream>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int n,x,f[1000010],maxap,elmaj;
int main() {
    fin>>n;
    for (int i=1;i<=n;i++) {
		fin>>x;
		f[x]++;
		if (f[x]>maxap) {
			maxap=f[x], elmaj=x;
		}
    }
    if (maxap>=n/2+1)
		fout<<elmaj<<" "<<maxap;
	else
		fout<<-1;
    return 0;
}