Cod sursa(job #639299)

Utilizator ContraPunctContrapunct ContraPunct Data 23 noiembrie 2011 00:16:16
Problema Elementul majoritar Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include<fstream>
#include<bitset>
#include<map>
using namespace std;

const int Nmax =2000000000;

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

map<int,int> hh ;
int n;
int nr;

void Solve()
{
	fin>>n;
	int x;

	for(int i=1;i<=n;i++)
	{
		fin>>x;
		if( hh.find(x) == hh.end() )
		{
			hh.insert(make_pair(x,1));
		}
		else
			hh[x] = hh[x]+1;
	}
}

int Afisare()
{
	map<int,int>::iterator it;
	n= n/2+1;
	for ( it = hh.begin() ; it != hh.end(); it++ )
	if((*it).second >= n )
	{
		fout<<(*it).first<<" "<< (*it).second << endl;
		return 1;
	}
	return 0;
}


int main()
{
	Solve();
	if ( Afisare() == 0 ) 
		fout<<"-1\n";
	fout.close();
	fin.close();
	return 0;
}