Cod sursa(job #633979)

Utilizator marius135Dumitran Adrian Marius marius135 Data 15 noiembrie 2011 11:17:39
Problema Elementul majoritar Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <fstream>
#include <algorithm>

using namespace std;

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

const int N=1000001;

int v[N],n,win,contor;

void afisare() {
	for( int i = 1; i <= n; ++i)
		out<<v[i] <<" ";
	out<<"\n";
}
int main(){
	int i;
	in>>n;
	for(i=1;i<=n;++i){
		in>>v[i];
	}
	// afisare();
	sort (v + 1, v + n + 1);
	// afisare();
	int count = 1, val = v[ 1];
	int max = 0, cine = 3;
	for( int i = 2; i <= n; ++i) {
		if( v[i] != v[ i - 1]) {
			count = 0;
			val = v[i];
		}
		count++;
		if( count > max) {
			max = count;
			cine = v[ i ];
		}
	}
	if( max > n/2) 
		out<<cine<<" "<<max;
	else out<<"-1";
		
	
}