Pagini recente » Cod sursa (job #1246215) | Cod sursa (job #1539289) | Cod sursa (job #2862719) | Cod sursa (job #1097333) | Cod sursa (job #2857744)
#include <fstream>
#include <unordered_map>
using namespace std;
int n, x, valSol, nrSol;
unordered_map<int, int> u;
int main() {
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
fin >> n;
for (int i = 1; i <= n; i++) {
fin >> x;
if (u.find(x) != u.end()) {
// int nr = u.find(x)->second;
// u.erase(x);
// u.emplace(x, nr+1);
u.at(x)++;
} else {
u.emplace(x, 1);
}
}
for (auto &a:u) {
if (a.second > n / 2) {
nrSol = a.second;
valSol = a.first;
}
}
if (!nrSol) {
fout << -1;
} else {
fout << valSol << " " << nrSol;
}
return 0;
}