Cod sursa(job #3291006)
Utilizator | Data | 2 aprilie 2025 21:09:51 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int n,k,x;
unordered_map <int,int> mp;
int32_t main()
{
f>>n;
for(int i=1; i<=n; i++)
f>>x, mp[x]++;
for(auto it:mp)
if(it.second>=n/2+1)
{g<<it.first<<' '<<it.second; return 0;}
g<<-1;
return 0;
}