Pagini recente » Cod sursa (job #2177273) | Cod sursa (job #2728773) | Cod sursa (job #1135075) | Cod sursa (job #895472) | Cod sursa (job #2802244)
#include <bits/stdc++.h>
using namespace std;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
int tip,nrtip,ap;
int n,a[1000005];
int main()
{
in >> n;
for (int i = 1; i <= n; i++)
{
in >> a[i];
if (nrtip == 0)
{
tip = a[i];
nrtip = 1;
}
else
{
if (a[i] == tip)
nrtip++;
else
nrtip--;
}
//cout << a[i] << " " << tip << " " << nrtip << '\n';
}
for (int i = 1; i <= n; i++)
if (a[i] == tip)
ap++;
if (ap >= n / 2 + 1)
out << tip << " " << ap;
else
out << -1;
return 0;
}