Pagini recente » Cod sursa (job #3153756) | Cod sursa (job #2770082) | Cod sursa (job #1459826) | Cod sursa (job #8067) | Cod sursa (job #1460314)
#include<cstdio>
using namespace std;
int v[1000000], N, X, nr, i, k;
int main()
{
freopen("elmaj.in","r",stdin);
freopen("elmaj.out","w",stdout);
scanf("%d", &N);
for (i = 0; i < N; i++)
{
scanf("%d", &v[i]);
if (v[i] == X)
k++;
else
k--;
if (k == -1)
{
X = v[i];
k = 0;
}
}
if ( k != -1)
for (i = 0; i < N; i++)
if ( v[i] == X)
nr++;
if (nr > N/2)
printf("%d %d\n", X, nr);
else
printf("-1\n");
}