The Lead Game

import java.util.Scanner;

public class TheLeadGame {

	public static void main(String[] args)
	{
		Scanner one = new Scanner(System.in);
		
		int N = one.nextInt();
		
		int leader = 0, total=-1,num = 0, player = 0;
		
		int[] array = new int[N];
		
		int[] array2 = new int[N];
		
		for(int i=0;i<N;i++)
		{
			int W =one.nextInt();
			int L = one.nextInt();
			
			int lead = Math.abs(W-L);
			array[i]=lead;
			
			if(W>L)
			{
				leader = 1;
			}
			else
			{
				leader = 2;
			}
			array2[i] = leader;
			
			
		}
		
		
		for(int j=0;j<N;j++)
		{
			
			num=array[j];
			if(num>total)
			{
				total=num;
				player = array2[j];
			}
		}
		
		System.out.println(player+"  "+total);
		
	
		one.close();
	}
	}
1 Like

The corrected solution: https://www.codechef.com/viewsolution/18605106

  1. Don’t create a public class. Codechef throws a RE in such a case.
  2. Always include the question link and your submitted solution link.

Now, considering your solution, your code has a small mistake; the problem asks to calculate the cumulative lead and compare them. You have calculated the current lead.

In other words, you have compared the absolute difference of score of Player A and B in that particular round, but, according to the problem, you need to compare the sum of scores of A and B upto that particular round…

Hope it helps…:slight_smile:

You can create a public class but the name of class has to be Main then.

Thanks, It helped a lot