Pagini recente » Cod sursa (job #1550881) | Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #3361057)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int n, v[1000001], elmaj, aux;
int main()
{
fin>>n;
for(int i=0; i<n; i++)
{
fin>>v[i];
if(aux==0)
{
elmaj=v[i];
}
if(v[i]==elmaj)
{
aux++;
}
else
{
aux--;
}
}
aux=0;
for(int i=0; i<n; i++)
{
if(v[i]==elmaj)
{
aux++;
}
}
if(aux>n/2)
{
fout<<elmaj<<" "<<aux;
}
else
{
fout<<-1;
}
return 0;
}