Pagini recente » Cod sursa (job #3151990) | Cod sursa (job #791073) | Cod sursa (job #573173) | Cod sursa (job #1401837) | Cod sursa (job #1790594)
#include <fstream>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int n,i,v[3000001],fr,elm;
int main()
{
fin>>n;
for(i=1;i<=n;i++)
fin>>v[i];
fr=1;elm=v[1];
for(i=2;i<=n;i++)
if(v[i]==elm) fr++;
else{
fr--;
if(fr<0)
fr=1,elm=v[i];
}
fr=0;
for(i=1;i<=n;i++)
if(v[i]==elm)
fr++;
if(fr>n/2+1)
fout<<elm<<' '<<fr;
else fout<<"-1";
return 0;
}