Cod sursa(job #2897981)

Utilizator SeracovanuEdwardSeracovanu Edward SeracovanuEdward Data 5 mai 2022 16:42:20
Problema Elementul majoritar Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <bits/stdc++.h>

using namespace std;

map <int,int> mp;
int n , x;

int main()
{
    freopen("elmaj.in" , "r" , stdin);
    freopen("elmaj.out" , "w" ,stdout);
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    cin >> n;
    for(int i = 1;i <= n; ++i){
        cin >> x;
        ++mp[x];
    }
    int maxx = -1,maxxval = 0;
    for(auto x:mp){
        if(maxx < x.second){
            maxx = x.second;
            maxxval = x.first;
        }
    }
    cout << maxxval << " " << maxx;
}