Cod sursa(job #2147866)

Utilizator FunnyStockyMihnea Andreescu FunnyStocky Data 1 martie 2018 08:57:31
Problema Elementul majoritar Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <fstream>
#include <map>

using namespace std;

ifstream cin("elmaj.in");
ofstream cout("elmaj.out");

const int nmax=1000000;
map<int,int> ap;
int n,v[nmax+5];
int nr,X;
bool gasit=0;
int main()
{
    cin>>n;
    nr=n/2+1;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        ap[v[i]]++;
        if(!gasit && ap[v[i]]==nr)
        {
            gasit=1;
            X=v[i];
        }
    }
    if(gasit==0)
        cout<<-1;
    else
        cout<<X<<" "<<ap[X]<<"\n";
	return 0;
}
/**


**/