Cod sursa(job #1987860)

Utilizator ArctopusKacso Peter-Gabor Arctopus Data 1 iunie 2017 12:17:58
Problema Elementul majoritar Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <queue>
#include <climits>
#include <map>

#define ll long long
#define pb push_back

using namespace std;

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

const int NLIM = 1e6 + 10;

int N;

map< int, int > m;

int elmaj = -1;

int main()
{
    ios::sync_with_stdio( false );

    fin >> N;
    for( int i = 0; i < N; ++i )
    {
        int x;
        fin >> x;

        m[x] += 1;
        if( m[x] >= ( ( N / 2 ) + 1 ) )
            elmaj = x;
    }


    fout << elmaj << " ";
    if( elmaj != -1 )
        fout << m[elmaj];

    return 0;
}