Cod sursa(job #3167963)

Utilizator proflaurianPanaete Adrian proflaurian Data 11 noiembrie 2023 12:29:59
Problema Elementul majoritar Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
unordered_map<int,int> cnt;
int n;
int main()
{
    f>>n;
    for(int i=1; i<=n; i++)
    {
        int x;
        f>>x;
        cnt[x]++;
    }

    for(auto it:cnt)
        if(it.second>=n/2+1)
        {
            g<<it.first<<' '<<it.second<<'\n';
            return 0;
        }
    g<<"-1\n";
    return 0;
}