Pagini recente » Cod sursa (job #166764) | Cod sursa (job #96651) | Cod sursa (job #569097) | Cod sursa (job #1202162) | Cod sursa (job #3265340)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
int cnt[3000001] , v[3000001];
int main()
{
int n, max=-1 , k , a;
in>>n;
for(int i=0 ; i<= n-1 ; i++)
{
in>>v[i];
for(int j=i-1 ; j>=0 ; j--)
if(v[i]==v[j])
{
cnt[i]=cnt[j]+1;
if(cnt[i]>max)
{
max=cnt[i];
k=i;
}
break;
}
}
if(max+1>=(n/2)+1)
out<<v[k]<<" "<<max+1;
else
out<<-1;
return 0;
}