Pagini recente » Cod sursa (job #2481497) | Cod sursa (job #1003383) | Cod sursa (job #297514) | Cod sursa (job #3136395) | Cod sursa (job #1405092)
#include <cstdio>
using namespace std;
int a[1000000],i,nr,ct,n,vot,q;
int main()
{freopen("elmaj.in","r",stdin);
freopen("elmaj.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
q=1;
vot=1;
for(i=2;i<=n;i++)
{if(a[i]==a[q])vot++;
else vot--;
if(vot==0){q=i;vot=1;}
}
nr=a[q];
for(i=1;i<=n;i++)
if(nr==a[i]) ct++;
if(ct>=n/2+1) printf("%d",nr);
else printf("-1");
}