Cod sursa(job #1479259)

Utilizator tudorgalatanRoman Tudor tudorgalatan Data 30 august 2015 20:54:11
Problema Elementul majoritar Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 0.47 kb
// Galatan Tudor - Ion Luca Theoretical High School
// Husi, Romania, Su, August 30, 2015

#include <fstream>

#define R 1000001

using namespace std;

ifstream in ("elmaj.in");
ofstream out ("elmaj.out");

int No_App[R];
int n, i, x, ct, Maj_Elm;

int main ()
{
	in >> n;
	for (i=0; i<n; i++)
	{
		in >> x;
		No_App[x]++;
		if (No_App[x] > No_App[Maj_Elm])
			Maj_Elm = x;
	}
	if (No_App[Maj_Elm] >= n/2+1)
		out << Maj_Elm << " " << No_App[Maj_Elm];
	else
		out << "-1";
	return 0;
}