Cod sursa(job #3226766)
Utilizator | Data | 22 aprilie 2024 19:16:22 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
map<int, int> M;
int i, n, x;
int main()
{
f >> n;
for (i = 1; i <= n; i++)
{
f >> x;
M[x]++;
}
for (auto e : M)
if (e.second >= (n+1)/2)
{
g << e.first << " " << e.second << "\n";
return 0;
}
g << "-1\n";
return 0;
}