Pagini recente » Cod sursa (job #2942762) | Cod sursa (job #1200667) | Cod sursa (job #290616) | Cod sursa (job #1119858) | Cod sursa (job #2905183)
#include <bits/stdc++.h>
#define Nmax 1000000
using namespace std;
ifstream fin ("elmaj.in");
ofstream fout ("elmaj.out");
int n,i,v[Nmax],cand,nrapp;
int main()
{
fin>>n;
for (i=0;i<n;i++)
{
fin>>v[i];
if (v[i]==cand)
nrapp++;
else if (nrapp==0)
{
cand=v[i];
nrapp++;
}
else nrapp--;
}
nrapp=0;
for (i=0;i<n;i++)
if (cand==v[i])
nrapp++;
if (nrapp>=n/2+1)
fout<<cand<<' '<<nrapp;
else fout<<"-1";
return 0;
}