Cod sursa(job #1672783)

Utilizator teosposibSposib Teodor Alexandru teosposib Data 3 aprilie 2016 03:02:55
Problema Elementul majoritar Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include <fstream>
#include<iostream>
#include<map>
using namespace std;
ifstream f("majoritar.in");
ofstream g("majoritar.out");
map<long,long> v;
map<long,long>::iterator it;

int main()
{long N,max=0,x,ind;
 f>>N;
 for(long i=1;i<=N;i++)
    {f>>x;
     it=v.find(x);
     if (it!= v.end()) v[x]++;
     else v[x]=1;
     if(v[x]>max) {max=v[x];ind=x;}}
 if(v[ind]<N/2) g<<-1;
 else g<<ind<<" "<<v[ind];

    return 0;
}