Cod sursa(job #3312811)

Utilizator depevladVlad Dumitru-Popescu depevlad Data 30 septembrie 2025 01:46:20
Problema Elementul majoritar Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.59 kb
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifndef LOCAL
  freopen("elmaj.in", "r", stdin);
  freopen("elmaj.out", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> arr(n);
  int m{0};
  int c{0};
  for (int i = 0; i < n; ++i) {
    int e;
    cin >> e;
    if (!c) {
      ++c;
      m = e;
    } else {
      if (m != e) {
        --c;
      } else {
        ++c;
      }
    }
    arr[i] = e;
  }
  if (!c) {
    cout << "-1\n";
  } else {
    cout << m << " " << count(arr.begin(), arr.end(), m) << "\n";
  }
  return 0;
}