Cod sursa(job #2247210)

Utilizator Cristian25Cristian Stanciu Cristian25 Data 27 septembrie 2018 23:39:07
Problema Elementul majoritar Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <fstream>
#define inputfile "elmaj.in"
#define outputfile "elmaj.out"
#define sz 200000001

using namespace std;
ifstream f(inputfile);
ofstream g(outputfile);
unsigned int N, ap[sz], rez, cmax;
int main()
{
    f >> N;
    unsigned int v[N];
    for(unsigned int i = 0; i < N; ++i)
    {
        f >> v[i];
        ++ap[v[i]];
        if(cmax < ap[v[i]])
        {
            cmax = ap[v[i]];
            rez = v[i];
        }
    }
    cmax > N / 2 ? g << rez << ' ' << cmax : g << - 1;
    return 0;
}