The Lead Game..Can someone tell me what's wrong with this code.The code runs perfect in eclipse.

import java.util.Scanner;

class the_lead_game {

static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
	int n,a[],b[],i,diff[][],max,lead = 0;
	//Enter n ::
	n = scan.nextInt();
	a = new int[n];
	b = new int[n];
	diff = new int[n][2];
	for(i=0;i<n;i++)
	{
		//Enter a and b ::
		a[i] = scan.nextInt();
		b[i] = scan.nextInt();
	}
	
	for(i=0;i<n;i++)
	{
			if(a[i] > b[i])
			{
			diff[i][0] = a[i] - b[i];
			diff[i][1] = 1;
			}
			if(b[i] > a[i])
			{
				diff[i][0] = b[i] - a[i];
				diff[i][1] = 2;
			}
	}
	max = diff[0][0];
	lead = diff[0][1];
	for(i=0;i<n;i++)
	{
			if(diff[i][0] > max) 
			{
				max = diff[i][0];
				lead = diff[i][1];
			}
	}
	System.out.println(lead+" "+max);
	
}

}

Hi, @ritu9898

You have fallen into the same trap as others – misconceiving the problem.

To solve this on your own, set aside your solution for a while – if possible, try not to think about it, because it represents an understanding that doesn’t match the problem statement.

Instead, reread the problem carefully… https://www.codechef.com/problems/TLG

By hand, just following the problem description (not your code), try the following example:

4
140 82
89 134
90 110
112 164

This is similar to, but different from, the example in the problem statement. If you follow the problem statement instructions correctly, you should end up with an answer that is different from what your code yields.

Hopefully that will reveal the issue to you. Good luck!