Cod sursa(job #2186979)

Utilizator OldpugAlex Ionescu Oldpug Data 26 martie 2018 09:25:46
Problema Elementul majoritar Scor 0
Compilator cpp Status done
Runda bpc10 Marime 0.46 kb
#include <fstream>
#include <functional>
#include <map>
#include <cstdint>

int main() {
  std::ifstream in{"elmaj.in"};
  std::ofstream out{"elmaj.out"};

  std::map<int32_t, int32_t, std::greater<int32_t>> map;

  int32_t n{};
  in >> n;

  int32_t i{};
  while (in >> i)
    ++map[i];

  auto fst{map.begin()};
  auto elem{fst->first};
  auto count{fst->second};

  if (count > n / 2)
    out << elem << ' ' << count;
  else
    out << -1;
}