Pagini recente » Cod sursa (job #1501841) | Cod sursa (job #2812874) | Cod sursa (job #3156843) | Cod sursa (job #1512058) | Cod sursa (job #2148746)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("elmaj.in");
ofstream fout ("elmaj.out");
const int Nmax = 1000005;
int a[Nmax];
int main()
{
int x , maj , s , n;
fin >> n;
fin >> x;
s = 1;
maj = x;
a[1] = x;
for(int i = 2 ; i <= n ; i++)
{
fin >> x;
if(maj != x)
s--;
else s++;
if(s <= 0)
{
s = 1;
maj = x;
}
a[i] = x;
}
s = 0;
for(int i = 1 ; i <= n ; i++)
s += (maj == a[i]);
if(s > n / 2)
fout << maj << " " << s << "\n";
else fout << "-1\n";
fin.close();
fout.close();
return 0;
}