Pagini recente » Cod sursa (job #1810460) | Cod sursa (job #1885001) | Cod sursa (job #1098639) | Cod sursa (job #2661414) | Cod sursa (job #2183920)
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
int ap[110017][2];
const int M=110017;
int h(int x)
{
return x%M;
}
int main()
{
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
vector < int > v[110017];
int p, n, i, j, ind, max, apmax=0, x;
fin >> n;
for (i=0; i<n; i++)
{
fin >> x;
p=0;
ind=h(x);
for (j=1; j<v[ind].size()+1; j++)
if (x==v[ind][j])
p=1;
if (ap[ind][0]==0)
{
ap[ind][0]=1;
ap[ind][1]=x;
}
else if (ap[ind][1]==x)
ap[ind][0]++;
}
p=0;
for (i=0; i<110017; i++)
{
if (p)
break;
if (ap[i][0]>n/2)
{
p=1;
apmax=ap[i][0];
max=ap[i][1];
}
}
if (p)
fout << max << " " << apmax;
else
fout << -1;
return 0;
}