Cod sursa(job #1933413)

Utilizator al_k_ponyClaudiu Babin al_k_pony Data 20 martie 2017 18:18:40
Problema Elementul majoritar Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
# include <bits/stdc++.h>
# define maxn 100001
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define pb push_back
# define mp make_pair
//# define int ll
using namespace std;
const int inf = INT_MAX;

map<int,int>a;
int mj;

int32_t main(){_
    freopen("elmaj.in","r",stdin);
    freopen("elmaj.out","w",stdout);
	int n;
	cin >> n;
	for(int i = 1;i<=n;i++)
	{
		int x;
		cin >> x;
		a[x]++;
		if(!mj && a[x] >= (n/2) + 1) mj = x;
	}
    if(mj) rc(mj << ' ' << a[mj]);
	rc(-1);
}