Pagini recente » Cod sursa (job #2298310) | Cod sursa (job #1332438) | Monitorul de evaluare | Cod sursa (job #961872) | Cod sursa (job #2950594)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int main()
{
int n, cnt=0;
long long cand;
long long *v = new long long[1000000];
stack <long long> x;
fin >> n >> v[0];
x.push(v[0]);
for(int i=1; i<n; i++) {
fin >> v[i];
if(!x.empty() && x.top()!=v[i]) {
x.pop();
} else {
x.push(v[i]);
}
}
if(x.empty()) {
fout << -1;
} else {
cand=x.top();
for(int i=0; i<n; i++) {
if(v[i]==cand) {
cnt++;
}
}
if(cnt>=(n/2)+1) {
fout << cand << " " << cnt;
} else {
fout << -1;
}
}
delete[] v;
return 0;
}