Cod sursa(job #2718172)

Utilizator Stefan_XTRadu Stefan Rares Stefan_XT Data 8 martie 2021 15:48:06
Problema Suma si numarul divizorilor Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n;
    vector<int> v;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        v.push_back(x);
    }

    int cand = v[0], vot = 0;
    for (auto x : v)
    {
        if (x == cand)
            vot++;
        else
            vot--;
        if (vot == 0) cand = x, vot = 1;
    }

    if (vot > 0)
    {
        vot = 0;
        for (auto x : v)
            if (x == cand) vot++;
    }

    if (vot > n / 2) cout << "DA " << cand;
    else cout << "NU";

    return 0;
}