Cod sursa(job #3312596)

Utilizator Boita_DavidBoita David Andrei Boita_David Data 29 septembrie 2025 10:05:10
Problema Elementul majoritar Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include<iostream>
#include<fstream>

using namespace std;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
int a[100005], b[100005];
 int main(){
     long long n; bool k = false;
     in >> n;
     for (int i = 0; i < n; i++)
        cin >> a[i];
     for (int i = 0; i < n; i++) {
        b[a[i]]++;
    }
    for (int i = 0; i < n; i++) {
         if (b[i] > n/2){
                k = true;
             out << a[i] << " " << b[a[i]];
         }
    }
    if (k == false)
        out << "-1";
 return 0;}