Pagini recente » Cod sursa (job #242128) | Cod sursa (job #2160290) | Cod sursa (job #535627) | Cod sursa (job #2596752) | Cod sursa (job #1249472)
#include <fstream>
#define Nmax 1000100
using namespace std;
int candidate, votes, N, A[Nmax];
void Solve() {
candidate = A[1];
votes = 1;
for(int i = 2; i <= N; i++) {
if(candidate == A[i])
votes++;
else
votes--;
if(votes == 0) {
candidate = A[i];
votes = 1;
}
}
votes = 0;
for(int i = 1; i <= N; i++)
if(A[i] == candidate)
++votes;
if(votes < N / 2 + 1)
candidate = 0;
}
void Read() {
ifstream in("elmaj.in");
in >> N;
for(int i = 1; i <= N; i++)
in >> A[i];
in.close();
}
void Write() {
ofstream out("elmaj.out");
if(candidate != 0)
out << candidate << ' ' << votes << '\n';
else
out << "-1\n";
out.close();
}
int main() {
Read();
Solve();
Write();
return 0;
}