Cod sursa(job #2076448)

Utilizator ImbuzanRaduImbuzan Radu ImbuzanRadu Data 26 noiembrie 2017 16:48:57
Problema Elementul majoritar Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream>
#include <fstream>

using namespace std;

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

long long  ap[100000000];

int main()
{
    int n, maxx = 0, ok = 0, c = 0;
    long long a[100000000]
    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;
}