Cod sursa(job #1496039)

Utilizator daniel.grosuDaniel Grosu daniel.grosu Data 4 octombrie 2015 10:12:08
Problema Elementul majoritar Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.56 kb
#define REP(a,b) for(int a=0; a<(b); ++a)
#define REP2(a, b) for(int a=1; a<=(b); ++a)
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define BCK(a,b,c) for(int a=(b)-1; a>=(c); --a)
#define BCK2(a,b,c) for(int a=(b); a>(c); --a)
#define FWDS(a,b,c,d) for(int a=(b); a<(c); a+=d)
#define ALL(a) (a).begin(), (a).end()
#define SIZE(a) ((int)(a).size())
#define VAR(x) #x ": " << x << " "
#define FILL(x,y) memset(x,y,sizeof(x))
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
#define x first
#define y second
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define l(n) (n<<1)
#define r(n) ((n<<1)+1)
#define f(n) (n>>1)
#define lsb(a) (a&-a)

#include<vector>
#include<stack>
#include<queue>
#include<algorithm>

using namespace std;
#ifndef ONLINE_JUDGE
#include<fstream>
ifstream cin("elmaj.in");
ofstream cout("elmaj.out");
#else
#include<iostream>
#endif

const int NMAX = 1000000;
const int dx[] = {0, 0, -1, 1}; //1,1,-1,1};
const int dy[] = {-1, 1, 0, 0}; //1,-1,1,-1};

typedef long long LL;
typedef pair<int, int> PII;
typedef long double K;
typedef pair<K, K> PKK;
typedef vector<int> VI;

int n, A[NMAX], k, curr;

int main() {
    FAST;
    cin>>n;
    REP(i,n)
        cin>>A[i];
    
    REP(i,n)
    {
        if(k==0)
        {
            curr=A[i];
            k=1;
        }
        else 
        if(A[i] == curr)
            k++;
        else
            k--;
    }

    int rs=0;
    REP(i,n)
    {
        if(A[i] == curr)
            rs++;
    }

    if(rs >= n/2 + 1)
        cout<<curr<<" "<<rs;
    else
        cout<<-1;

    return 0;
}