Pagini recente » Cod sursa (job #189662) | Cod sursa (job #2942074) | Cod sursa (job #1979629) | Cod sursa (job #2091951) | Cod sursa (job #1367395)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
const int maxn = 1000005;
int n, best, cnt = -1, a[maxn];
int main() {
fin >> n;
for(int i = 1 ; i <= n ; ++ i) {
fin >> a[i];
if(cnt <= 0) {
best = a[i];
cnt = 0;
}
if(best == a[i])
++ cnt;
else
-- cnt;
}
int cnt = 0;
for(int i = 1 ; i <= n ; ++ i)
if(a[i] == best)
++ cnt;
if(cnt >= n / 2 + 1)
fout << best << ' ' << cnt << '\n';
else
fout << "-1\n";
}