Pagini recente » Cod sursa (job #1396153) | Cod sursa (job #1287858) | Cod sursa (job #953069) | Cod sursa (job #1013516) | Cod sursa (job #1190039)
#include<fstream>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int n,nr,k,cand,a[1000005];
int main()
{
int i;
fin>>n;
cand=-1;
for (i=1;i<=n;++i)
{
fin>>a[i];
if (!k)
cand=a[i], k=1;
else
{
if (cand==a[i]) ++k;
else --k;
}
}
if (cand<0)
{
fout<<"-1\n";
return 0;
}
for (i=1;i<=n;++i)
if (cand==a[i]) ++nr;
if (nr>n/2)
fout<<cand<<" "<<nr<<"\n";
else
fout<<"-1\n";
return 0;
}