Pagini recente » Cod sursa (job #1825479) | Cod sursa (job #1101553) | Cod sursa (job #2129864) | Cod sursa (job #1622496) | Cod sursa (job #2381361)
#include <fstream>
using namespace std;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
int V[100005], 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;
}