# Cod sursa(job #1607401)

Utilizator Data 21 februarie 2016 02:55:24 Elementul majoritar 100 cpp done Arhiva educationala 1.71 kb
``````#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define mpair make_pair
#define endl "\n"
#define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define pushb push_back
#define pushf push_front
#define popb pop_back
#define popf pop_front
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define X first
#define Y second
#define ashar(a) cout << fixed << setprecision((a))
#define reset(a,b) memset(a, b, sizeof(a))
#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)
#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

ll lnno(ll a, ll b) { return (a ? lnno(b%a, a) : b); }
ll power(ll a, ll n) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; }
ll power(ll a, ll n, ll mod) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; p %= mod; } n >>= 1; a *= a; a %= mod; } return p % mod; }

const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int n_ = 1e6 + 2;
//const ld  PI = acos(-1.0);

//////////////////////////// START THE CODE WRITING ////////////////////////////

ifstream  in("elmaj.in");
ofstream out("elmaj.out");

int v[n_];

int main(){
int n;
in >> n;

for (int i = 0; i < n; i++)
in >> v[i];

sort(v, v + n);
int i = 0,aux ;
bool ndone = true;
while (ndone && i < n)
{
for (aux = 0; v[i] == v[i + aux]; aux++);
if (aux >= n / 2 + 1) ndone = false;
else i += aux;
}

if (ndone) out << -1 << endl;
else
out << v[i] << " " << aux << endl;
return 0;
}``````