What's wrong with my code?

, ,

The problem name is The Lead Game[easy section TLG].I’ve tried all possible test cases, read all comments, even seen some solutions(I shouldn’t have done that) and now come to the last resort.HELP ME[No. It’s not the usual cumulative error]

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.BufferedReader;

public class TheLeadGame {
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			PrintWriter pw = new PrintWriter(System.out);
			int t = Integer.parseInt(br.readLine());
			boolean play1 = false, play2 = false;
			long diff = 10000, max = -1, sum1 = 0, sum2 = 0;
			while(t>0){
				String str[] = br.readLine().split(" ");
				int player1 = Integer.parseInt(str[0]);
				int player2 = Integer.parseInt(str[1]);	
				sum1 += player1;
				sum2 += player2;
				if(sum1>sum2){
					diff=sum1-sum2;
					if(diff>max){
						max = diff;
						play1 = true;
					}
				}
				else{
					diff=sum2-sum1;
					if(diff>max){
						max = diff;
						play2 = true;
					}
				}
				t--;
			}	
			if(play1 == true){
				pw.println("1 "+max);
			}
			else{
				pw.println("2 "+max);
			}
			pw.flush();
		}
		catch(IOException e){
			e.getMessage();
		}
	}
}

Help me and if possible give some test cases as applicable

@saifudin:

Change player1=false when player2=true and vice versa, because according to your solution if player1 leads in any set his variable remains true without considering the player2’s lead.

AC solution for reference

2 Likes

Thank You @squal,
A minor bug but big WA…
Thanks a lot for your help.Appreciate it.

happy to have helped :slight_smile: