The Lead Game , What's wrong with my code ?

The code is for question The Lead Game ,its showing wrong answer while submitting but running perfectly on ideone.com .please help .

#include<stdio.h>
int main()
{
int winner,t,i,a[10001],b[10001],leader[10001],j,temp1,temp2,temp3;
scanf("%d",&t);
for(i=0;i<t;i++)
{
	scanf("%d%d",&a[i],&b[i]);
}
for(i=0;i<t;i++)
{
	if(a[i]>b[i])
	leader[i]=a[i]-b[i];
	else
	leader[i]=b[i]-a[i];
}
for(i=1;i<t;i++)
{       if(leader[i-1]>leader[i])
	leader[i]=leader[i-1]-leader[i];
	else
	leader[i]=leader[i]-leader[i-1];
}
for(i=0;i<t-1;i++)
{
	for(j=0;j<t-i-1;j++)
	{
		if(leader[i]<leader[i+1])
		{
			temp1=leader[i];
			leader[i]=leader[i+1];
			leader[i+1]=temp1;
			temp2=a[i];
			a[i]=a[i+1];
			a[i+1]=temp2;
			temp3=b[i];
			b[i]=b[i+1];
			b[i+1]=temp3;
		}
	}
}
if(a[0]>b[0])
winner=1;
else
winner=2;
printf("%d %d",winner,leader[0]);
return 0;
}

For the given testcase, your code may work…but it is not correct.

here you are storing the lead values of each round in the array leader[10000].

Those lead values are actually not a[i]-b[i]…it is actually

the sum of the scores of the player1 upto the "i"th round - the sum of the scores of the player2 till "i"th round…

so take care of that leader[10000]…then your code may give AC for codechef compiler also :slight_smile:

If this helps…hope you can upvote and accept the answer…

All the Best :slight_smile:

2 Likes