Pagini recente » Cod sursa (job #316894) | Cod sursa (job #2933193) | Cod sursa (job #686315) | Cod sursa (job #1501209) | Cod sursa (job #1641456)
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin ("elmaj.in");
ofstream fout ("elmaj.out");
int a[1000009], N;
int main ()
{
int i, j, k;
int x, cnt;
fin >> N;
for (i=1; i<=N; i++)
fin >> a[i];
x = a[1]; cnt = 1;
for (j=2; j<=N; j++)
{
if (a[j] != x) cnt--;
else cnt++;
if (cnt < 0) x = a[j];
}
k = 0;
for (j=1; j<=N; j++)
if (a[j] == x)
k++;
if (k>=(N+1)/2)
fout << x << " " << k << "\n";
else
fout << "-1";
fin.close();
fout.close();
return 0;
}