Cod sursa(job #1069231)

Utilizator mikeshadowIon Complot mikeshadow Data 29 decembrie 2013 16:49:28
Problema Elementul majoritar Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.04 kb
#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <math.h>
#include <set>
 
#define min(a,b) ((a<b)?a:b)
#define max(a,b) ((a<b)?b:a)
#define abs(a) ((a<0)?-a:a)
#define REP(i,a,b) \
	for (int i=a; i<=b; i++)
 
#define INF 10000000000001
 
using namespace std;


#ifndef TEST
ifstream fin ("strmatch.in");
ofstream fout ("strmatch.out");
#else
ifstream fin ("input.txt");
ofstream fout ("output.txt");
#endif
 
#define MAXN 1000000000
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pp;

int n;
int *a;
 
int main()
{
	fin>>n;

	a = new int[n];

	for (int i=0; i<n; i++)
		fin>>a[i];

	int scor = 0;
	int cur = a[0];

	for (int i=0; i<n; i++)
	{
		if (cur==a[i]) scor++;
		else scor--;
		if (scor<0) 
		{
			cur = a[i];
			scor = 1;
		}
	}

	scor=0;
	for (int i=0; i<n; i++)
		if (a[i]==cur) scor ++;

	if (scor*2>n) fout<<cur<<' '<<scor; else fout <<"-1";
	return 0;
}