Pagini recente » Cod sursa (job #2440724) | Cod sursa (job #1062777) | Cod sursa (job #1037588) | Cod sursa (job #1460703) | Cod sursa (job #639306)
Cod sursa(job #639306)
#include<fstream>
#include<bitset>
#include<map>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
map<long,int> hh ;
int n;
int nr;
int maxx ;
int m;
void Solve()
{
fin>>n;
long x;
m = n/2+1;
for(int i=1;i<=n;++i)
{
fin>>x;
if( maxx!=0 )
hh[maxx]++;
else
if( hh.find(x) == hh.end() )
{
hh.insert(make_pair(x,1));
}
else
{
++hh[x];
if(hh[x] >=m)
{
maxx = x;
}
}
}
if(maxx != 0 )
fout<<maxx<<" "<<hh[maxx]<<"\n";
else
fout<<-1;
}
int main()
{
Solve();
fin.close();
return 0;
}