Cod sursa(job #2493475)

Utilizator bondea_iur@yahoo.comIur Bondea [email protected] Data 16 noiembrie 2019 12:56:02
Problema Elementul majoritar Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.55 kb
#include<bits/stdc++.h>
using namespace std;
const int nmax = 1000005;

ifstream fin("elmaj.in");
ofstream fout("elmaj.out");



int n;
map<int, int> v;

void rezolva()
{

    int maxx = -1;
    int nr, x;
    fin >> n;
    for(int i = 1; i <= n; i ++)
    {
        fin >> x;
        v[x]++;
        if(maxx < v[x])
        {
            maxx = v[x];
            nr = x;
        }
    }
    if((n /2) + 1 <= maxx)
        fout << nr <<" " << maxx;
    else
        fout << -1;

}

int main()
{
    rezolva();
    return 0;
}