Pagini recente » Cod sursa (job #106243) | Cod sursa (job #851389) | Cod sursa (job #2603930) | Cod sursa (job #370021) | Cod sursa (job #3164873)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream input("elmaj.in");
ofstream output("elmaj.out");
int a[1000000], b[1000000], dbmaj=0, i, N, temp;
input>>N;
for(i=0; i<N; i++){
input>>a[i];
b[i]=a[i];
}
int bal=0, jobb=1;
while(jobb<N){
while(a[bal]==a[jobb] && jobb<N){
jobb++;
}
if(jobb<N){
a[bal]=-1;
a[jobb]=-1;
}
jobb++;
while(bal<N && a[bal]==-1){
bal++;
}
if(jobb==bal){
jobb++;
}
}
if(bal>=N || a[bal]==-1) output<<-1;
else {
for(i=0; i<N; i++){
if(b[i]==a[bal]) dbmaj++;
}
if(dbmaj>=N/2+1) output<<a[bal]<<" "<<dbmaj;
else output<<-1;
}
return 0;
}