Pagini recente » Cod sursa (job #2640162) | Cod sursa (job #751078) | Cod sursa (job #2190193) | Borderou de evaluare (job #2077881) | Cod sursa (job #2653098)
#include <fstream>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int n;
fin >> n;
unordered_map<int, int> counts;
for (int i = 0; i < n; i++) {
int x;
fin >> x;
auto it = counts.find(x);
if (it == counts.end()) {
counts[x] = 1;
} else {
it->second++;
}
}
auto it = max_element(counts.begin(), counts.end(),
[](auto &l, auto &r){return l.second < r.second;});
if (it->second > n/2) {
fout << it->first << ' ' << it->second;
} else {
fout << -1;
}
return 0;
}