Pagini recente » Cod sursa (job #649474) | Cod sursa (job #2378767) | Cod sursa (job #1400112) | Cod sursa (job #3153193) | Cod sursa (job #1400150)
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fs first
#define sc second
#define pob pop_back
#define pub push_back
#define eps 1E-7
#define sz(a) a.size()
#define count_one __builtin_popcount;
#define count_onell __builtin_popcountll;
#define fastIO ios_base::sync_with_stdio(false)
#define PI (acos(-1.0))
#define linf (1LL<<62)//>4e18
#define inf (0x7f7f7f7f)//>2e9
#define DEBUG 1
#ifdef DEBUG
#define D(x) x
#else
#define D(x)
#endif
#define MAXN 1000010
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int n, elmaj, elcount;
int a[MAXN];
int main()
{
int x;
elcount = 1;
fin >> n;
fin >> elmaj; a[0] = elmaj;
for(int i = 1; i < n; ++i) {
fin >> a[i];
if(a[i] == elmaj)
elcount++;
else if(elcount > 0)
elcount--;
else
elmaj = a[i], elcount = 1;
}
elcount = 0;
for(int i = 0; i < n; ++i) {
if(a[i] == elmaj)
elcount++;
}
if(elcount > (n >> 1))
fout << elmaj << " " << elcount;
else
fout << -1;
return 0;
}