Pagini recente » Cod sursa (job #2731195) | Cod sursa (job #1600652) | Cod sursa (job #2846016) | Cod sursa (job #1456274) | Cod sursa (job #2381362)
#include <fstream>
using namespace std;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
int V[1000005], n;
int main() {
in >> n;
for(int i=1; i<=n; i++)
in >> V[i];
int index = 0, candidat = 0, ap = 0;
for(int i=1; i<=n; i++) {
if(index == 0) {
candidat = V[i];
index = 1;
}
else {
if(V[i] == candidat)
index++;
else
index--;
}
}
for(int i=1; i<=n; i++) {
if(V[i] == candidat)
ap++;
}
if(ap < n/2 +1)
out << -1;
else
out << candidat << " " << ap;
return 0;
}