Cod sursa(job #2792308)

Utilizator 100pCiornei Stefan 100p Data 1 noiembrie 2021 13:47:19
Problema Elementul majoritar Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <bits/stdc++.h>
#define FILES freopen("elmaj.in","r",stdin);\
              freopen("elmaj.out","w",stdout);
#define fastio std::ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL);
#define add emplace_back
#define pb push_back
#define mp make_pair
#define md 666013
#define MAX 100000
using namespace std;
int n,a,cnt;
unordered_map <int,int> m;
int main()
{
    fastio
    FILES
    cin >> n;
    for(int i = 1;i <= n; ++i){
        cin >> a,m[a]++;
        if(m[a] > n / 2)
            cnt = a;
    }
    cout << cnt << ' ' << m[cnt];
}