Cod sursa(job #906174)

Utilizator micuhdPop Claudiu micuhd Data 6 martie 2013 16:10:29
Problema Elementul majoritar Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n;
long v[1000001];

int main()
{
long maxx=0,nrmax;
int i,x;

    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>x;
        v[x]++;
        if(v[x]>maxx)
        {
            maxx=v[x];
            nrmax=x;
        }

    }
    if(maxx>=(n/2)+1)
        g<<nrmax<<" "<<maxx;
    else
        g<<"-1";
    return 0;
}