Pagini recente » Cod sursa (job #1957781) | Cod sursa (job #1780420) | Cod sursa (job #2341437) | Monitorul de evaluare | Cod sursa (job #2648222)
//
// main.cpp
// elkmaj
//
// Created by Eusebiu Rares on 09/09/2020.
// Copyright © 2020 Eusebiu Rares. All rights reserved.
//
#include <iostream>
#include "fstream"
std::fstream in ("elmaj.in", std::ios::in) ;
std::fstream out ("elmaj.out", std::ios::out) ;
const int MV = 1e6 ;
//#define in std::cin
//#define out std::cout
int v[MV + 1] ;
int main(int argc, const char * argv[]) {
int n ; in >> n ;
int elmaj(-1), cnt(1) ;
for (int i = 1 ; i <= n ; ++ i) {
in >> v[i] ;
if (elmaj != v[i]) {
cnt -- ;
} else {
cnt ++ ;
}
if (cnt == 0) {
elmaj = v[i] ;
cnt ++ ;
}
}
cnt = 0 ;
for (int i = 1 ; i <= n ; ++ i) {
cnt += (elmaj == v[i]) ;
}
if (cnt >= n / 2 + 1) {
out << elmaj << ' ' << cnt ;
} else out << -1 ;
}