Pagini recente » Cod sursa (job #1598896) | Cod sursa (job #2346282) | Cod sursa (job #2233213) | Cod sursa (job #3830) | Cod sursa (job #1380103)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int n, a[MAXN], cnt, maj;
int main()
{
fin >> n;
for (int i = 1; i <= n; ++i)
fin >> a[i];
for (int i = 1; i <= n; ++i)
{
if (cnt == 0)
{
maj = a[i];
cnt++;
}
else if (a[i] == maj)
cnt++;
else
cnt--;
}
cnt = 0;
for (int i = 1; i <= n; ++i)
{
if (a[i] == maj)
cnt++;
}
if (cnt >= n / 2 + 1)
fout << maj << " " << cnt;
else
fout << -1;
return 0;
}