Pagini recente » Cod sursa (job #1246088) | Cod sursa (job #1509558) | Cod sursa (job #2089808) | Cod sursa (job #897827) | Cod sursa (job #1423470)
#include <fstream>
using namespace std;
int main() {
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
long long n, nr, cand = 0, cnt = 0;
fin >> n;
for (; n; n--) {
fin >> nr;
if (!cand) {
cand = nr;
cnt = 1;
} else if (nr == cand)
cnt++;
else cnt--;
}
fin.close();
ifstream fin2("elmaj.in");
fin2 >> n;
cnt = 0;
for (int i = 1; i <= n; i++) {
fin2 >> nr;
if (nr == cand)
cnt++;
}
if (cnt >= n / 2 + 1)
fout << cand << ' ' << cnt;
else fout << -1;
return 0;
}