Pagini recente » Cod sursa (job #2806711) | Cod sursa (job #2751826) | Cod sursa (job #1747970) | Cod sursa (job #1491054) | Cod sursa (job #3131486)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
const int NMAX = 1e6;
int a[NMAX+5];
int main()
{
int n, current_candidate, number_of_votes = 0, total_number = 0;
fin>>n;
for (int i = 1; i <= n; i++) {
fin>>a[i];
if (number_of_votes == 0) current_candidate = a[i];
if (a[i] == current_candidate) number_of_votes++;
else number_of_votes--;
}
for (int i = 1; i <= n; i++)
if (a[i] == current_candidate) total_number++;
if (total_number > n/2) fout<<current_candidate<<' '<<total_number;
else fout<<-1;
return 0;
}