Pagini recente » Cod sursa (job #2761434) | Cod sursa (job #769361) | Cod sursa (job #1555920) | Cod sursa (job #789384) | Cod sursa (job #1523022)
#include <iostream>
#include <fstream>
#include <unordered_map>
#define NMAX 1000005
using namespace std;
int x,n,Max,el;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
unordered_map<int,int> has;
int main()
{
in >> n;
for(int i=0;i<n;i++)
{
in >> x;
if(has.find(x)==has.end())
{
has.insert(make_pair(x,1));
}
else
{
has[x]++;
}
}
for(unordered_map<int,int>::iterator it=has.begin();it!=has.end();it++)
{
if((*it).second>Max)
{
el = (*it).first;
Max= (*it).second;
}
}
if(Max>n/2)
{
out << el << " " << Max;
}
else
{
out << -1;
}
return 0;
}