Cod sursa(job #1458110)

Utilizator stefan.petreaStefan Petrea stefan.petrea Data 6 iulie 2015 22:09:15
Problema Elementul majoritar Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <iostream>
#include <map>
using namespace std;

#define MAX 1000000
map<long,long> v;
long n;

/* 
 * www.infoarena.ro/problema/elmaj
 *
 * put elements into the v[] array
 * and update the maximum count and the
 * associated x
 */

int main() {
    map<long,long> m;
    cin >> n;
    long maxx=0;
    long maxv=-1;
    long i;
    for(i=0;i<n;i++) {
        long x;
        cin >> x;
        v[x]++;
        if(v[x] > maxv) {
            maxx = x;
            maxv = v[x];
        };
    };
    cout << maxx << " " << maxv << endl;
    return 0;
};