Pagini recente » Cod sursa (job #2272663) | preoji/clasament/10 | Clasament oni2011_ziua2 | Cod sursa (job #3261592) | Cod sursa (job #2438465)
# include <iostream>
# include <fstream>
# include <cmath>
using namespace std;
ifstream fi("elmaj.in");
ofstream fo("elmaj.out");
int n, x, elmaj, s;
int main ()
{
fi >> n;
for ( int i = 1; i <= n; ++i) {
fi >> x;
if ( s == 0) {
elmaj = x;
}
else
if ( x == elmaj)
++s;
else
--s;
}
fi.close();
ifstream fi("elmaj.in");
fi >> n;
s = 0;
for ( int i = 1; i <= n; ++i) {
fi >> x;
if ( x == elmaj)
++s;
}
if ( s >= n / 2 + 1)
fo << elmaj << " " << s;
else
fo << -1;
return 0;
}