Cod sursa(job #2076449)

Utilizator ImbuzanRaduImbuzan Radu ImbuzanRadu Data 26 noiembrie 2017 16:50:17
Problema Elementul majoritar Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("elmaj.in");
ofstream g("elmaj.out");

long long  ap[100000000];

int main()
{
    int n, a[100000], maxx = 0, ok = 0, c = 0;
    f>>n;
    for(int i=1;i<=n;i++){
        f>>a[i];
        ap[a[i]]++;
        if( a[i] > maxx ){
            maxx = a[i];
        }
}
    for(int i=1;i<= maxx && ok == 0; i++){
        if(ap[i] == n/2+1){
            g<<i<<" "<<ap[i];
            ok = 1;
            c = 1;
        }
    }
    if( c == 0)
        g<<-1;
    return 0;
}