Pagini recente » Istoria paginii runda/aaa | Cod sursa (job #2457976) | Cod sursa (job #2309295) | Cod sursa (job #1361029) | Cod sursa (job #2216537)
#include <fstream>
using namespace std;
ifstream fin ("elmaj.in");
ofstream fout ("elmaj.out");
const int Dim = 1000001;
int cnt,elmaj,x,n;
int main() {
fin >> n;
for ( int i = 1; i <= n; ++i) {
fin >> x;
if ( cnt == 0) {
elmaj = x;
cnt = 1;
}
else
{ if ( x == elmaj)
++cnt;
else
--cnt;
}
}
fin.close();
ifstream fin ("elmaj.in");
fin >> n;
cnt = 0;
for ( int i = 1; i <= n; ++i) {
fin >> x;
if ( x == elmaj)
++cnt;
}
if ( cnt > n / 2)
fout << elmaj << " " << cnt;
else
fout << -1;
}