Cod sursa(job #639318)

Utilizator ContraPunctContrapunct ContraPunct Data 23 noiembrie 2011 00:55:40
Problema Elementul majoritar Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include<fstream>
#include<cstdio>
#include<map>
using namespace std;

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

map<int,int> hh ;
int n;

inline void Solve()
{
	//freopen("elmaj.in","r",stdin);
	fin>>n;
	//scanf("%d",&n);
	int x, i;

	for( i=1;i<=n;++i)
	{
		fin>>x;
		//scanf("%d",&x);
		if( hh.find(x) == hh.end() )
		{
			hh.insert(make_pair(x,1));
		}
		else
			++hh[x];
	}
}

inline void Afisare()
{
	freopen("elmaj.out","w",stdout);
	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;
			printf("%d %d\n",it->first, it->second);
			return ;
		}
	//fout<<-1<<"\n";
	printf("-1\n");
}

int main()
{
	Solve();
	Afisare();
	//fout.close();
	//fin.close();
	return 0;
}