Cod sursa(job #1081416)

Utilizator costel93FMI - Dumea Eduard Constantin costel93 Data 13 ianuarie 2014 16:57:36
Problema Elementul majoritar Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <fstream>
#include <queue>
#include <vector>
#include <iostream>

using namespace std;

int v[500000000], i, pmax=1, n, a;

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

    fin>>n;
    for(i=1;i<=n;i++)
    {
        fin>>a;
        v[a]++;
        if(v[pmax]<v[a])
            pmax=a;
    }
    if(v[pmax]>n/2)
        fout<<pmax<<" "<<v[pmax];
    else
        fout<<-1;

    return 0;
}