Pagini recente » Cod sursa (job #2981600) | Borderou de evaluare (job #2034995) | Cod sursa (job #2763796) | Cod sursa (job #961203) | Cod sursa (job #645358)
Cod sursa(job #645358)
#include<fstream>
#include<iostream>
using namespace std;
long long n,potential,candidat,i,a;
long long v[1000001];
int main(){
ifstream f("elmaj.in");
ofstream g("elmaj.out");
f>>n;
for(i=1;i<=n;i++){
f>>a;
v[i]=a;
if(a==candidat)
potential++;
else
potential--;
if(potential<=0 && a!=candidat){
candidat=a;
potential=1;
}
}
if(potential>0){
g<<candidat;
potential=0;
for(i=1;i<=n;i++)
if(v[i]==candidat)
potential++;
g<<" "<<potential;
}
else
g<<"-1";
return 0;
}