Cod sursa(job #2964178)

Utilizator FunnyStockyMihnea Andreescu FunnyStocky Data 12 ianuarie 2023 16:09:09
Problema Elementul majoritar Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>

using namespace std;



signed main() {
#ifdef ONPC
  freopen("input.txt", "r", stdin);
#endif // ONPC

#ifndef ONPC
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  freopen ("elmaj.in", "r", stdin);
  freopen ("elmaj.out", "w", stdout);
#endif // ONPC

  int n;
  cin >> n;
  vector<int> a(n);
  int biruitor = -1, voturi = 0;
  for (auto &x : a) {
    cin >> x;
    if (!voturi) {
      biruitor = x;
      voturi = 1;
    } else {
      voturi--;
    }
  }
  voturi = 0;
  for (auto &x : a) {
    voturi += (x == biruitor);
  }
  if (voturi > n / 2) {
    cout << biruitor << " " << voturi << "\n";
  } else {
    cout << "-1\n";
  }

  return 0;
}
/**

**/