Cod sursa(job #2085002)

Utilizator sandu.m.mdMorari Sandu sandu.m.md Data 9 decembrie 2017 15:05:32
Problema Elementul majoritar Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
//don't work well

#include <iostream>
#include <fstream>

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

int main(){
long long int arr[1000001], n, element, emax = 0, key;
    fin >> n;
    for(long int i = 0; i < n; i++){
        fin >> element;
        arr[element]++;
        if(emax < arr[element]){
            emax = arr[element];
            key = element;
        }
        
    }

    if(emax >= n / 2 + 1)fout << key << " " << emax;
        else fout << "-1";
    fin.close();
    fout.close();
    return 0;
}