the lead game.....why am i getting wrong answer for my code..???

#include<stdio.h>
int main()
{
int n,i,leader,sum1=0,sum2=0,largest;
scanf("%d",&n);
int ply1[n],ply2[n],lead[n];
for(i=0;i<n;i++)
{
scanf("%d",&ply1[i]);
scanf("%d",&ply2[i]);

}
for(i=0;i<n;i++)
{
	if(ply1[i]>ply2[i])
	{
	
		
		lead[i]=ply1[i]-ply2[i];
	}
	else
	{
		
		lead[i]=ply2[i]-ply1[i];
	}
	
}
for(i=0;i<n;i++)
{
	sum1=sum1+ply1[i];
}
for(i=0;i<n;i++)
{
	sum2=sum2+ply2[i];
}
if(sum1>sum2)
{
	printf("1");
}
else
{
	printf("2");
}
largest=lead[0];
for(i=0;i<n;i++)
{
	if(largest<lead[i])
	largest=lead[i];
}
printf("%3d",largest);
return 0;

}

You did not get the question perfect. Read the problem statement carefully.

Concentrate on these points…

  • the player who had the maximum lead at the end of any round in the game is declared the winner.
  • notice how the lead is calculated from the second table in problem statement.

One clue from my side…

  • For any test case, you should get a different answer if the order of rounds are jumbled…
1 Like
//