What am i missing in the code? On the site www.ideone.com when i run the code it runs fine but here i get wrog answer.

#include<stdio.h>
#include<math.h>

int main()

{

int n;

scanf("%d",&n);
int b,a,c,diff[n],max_diff,diff1[n],diff2[n];
for(b=1;b<=n;b++)
{
	scanf("%d %d",&a,&c);
	diff[b]=a-c;
	if (a>c)
	{
		diff1[b]=a-c;
	}
	else
	{
		diff2[b]=c-a;
	}
}
max_diff=abs(diff[1]);
for (b=2;b<=n;b++)
{
	if (max_diff>abs(diff[b]))
	{
		max_diff=max_diff +0;
	}
	else
	{
		max_diff=abs(diff[b]);
	}
}
for (b=1;b<=n;b++)
{
	if (diff1[b]==max_diff)
	{
		printf("1 %d\n",max_diff);
	}
	else if (diff2[b]==max_diff)
	{
		printf("2 %d\n",max_diff);
	}
}

return 0;
}

First thing you cannot say that if your code is giving correct answer for sample test case so you’ll get AC.

Secondly, your code gives WA for this test case…

15
140 82
89 134
90 110
112 106
88 90
129 112
2 69
0 67
220 34
13 579
246 456
121 20
4 950
146 674
941 897

Your code’s output: 2 946

Actual Output: 2 2083

Read this explanation again,:

Consider the following score sheet for a game with 5 rounds:
    Round          Player 1       Player 2

      1             140                 82
      2              89                 134 
      3              90                 110 
      4              112              106
      5              88                  90 
The total scores of both players, the leader and the lead after
each round for this game is given below:
    Round             Player 1       Player 2     Leader     Lead

      1               140           	 82        Player 1     58
      2               229           	216       Player 1     13
      3               319           	326       Player 2      7
      4               431           	432       Player 2      1
      5               519           	522       Player 2      3
The winner of this game is Player 1 as he had the maximum lead (58
at the end of round 1) during the game. 

Error is:

You are not adding the previous score to the current score , i think you misunderstood problem.

You should add the previous score to the current score to calculate the lead .

See above mentioned second table you’ll understand the mistake… :slight_smile:

Or you may see my code here: CodeChef: Practical coding for everyone

it would help if provide a link to the question …

I think the question is about The Lead Game.
Link => TLG Problem - CodeChef