Pagini recente » Cod sursa (job #3218659) | Cod sursa (job #485899) | Cod sursa (job #999941) | Cod sursa (job #2793271) | Cod sursa (job #2377747)
#include <bits/stdc++.h>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
long long n, x, maj, cnt;
vector<long long> v;
int main()
{
f >> n;
for(int i = 0; i < n; ++i)
{
f >> x;
v.push_back(x);
if (cnt == 0)
maj = x,
cnt = 1;
else
if (maj == x)
++cnt;
else
--cnt;
}
long long totalCnt = count_if(v.begin(), v.end(), [](long long x) { return x == maj; });
if (totalCnt > n / 2)
g << maj << ' ' << totalCnt;
else
cout << -1;
return 0;
}