Cod sursa(job #3339826)

Utilizator filipdanieloanFilip-Daniel Oancea filipdanieloan Data 10 februarie 2026 13:26:33
Problema Elementul majoritar Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <bits/stdc++.h>
using namespace std;

int v[1000005];

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
#ifndef LOCAL
    freopen("elmaj.in", "r", stdin);
    freopen("elmaj.out", "w", stdout);
#endif

    int n; cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> v[i];
    }

    sort(v + 1, v + n + 1);
    int i = 1, j = 1, cnt = 0, voted = -1;
    while(i <= n) {
        j = i + 1;
        while(j <= n && v[j-1] == v[i])
            ++j;
        if(j - i > n/2) {
            voted = v[i];
            cnt = j - i;
            break;
        }
        i = j;
    }

    cout << voted << ' ' << cnt;

    return 0;
}