Showing wrong answer for correct output

Below is my code for Question

I have tried the below code for various inputs and it is giving me the desired output but while running the code on codechef it says wrong answer.
Please help

import java.util.StringTokenizer;

class CodeChef_TLG

public static void main(String[] args) throws IOException 
    String win = "";
    int lead = 0;
    int temp = 0;
    BufferedReader kin = new BufferedReader(
            new InputStreamReader(
    int totalGames = Integer.parseInt(kin.readLine());
    for (int i = 0; i < totalGames; i++)
        StringTokenizer st = new StringTokenizer(kin.readLine(), " ");
        int p1 = Integer.parseInt(st.nextToken());
        int p2 = Integer.parseInt(st.nextToken());
        lead = (p1 > p2) ? (p1 - p2) : (p2 - p1);
        if (lead > temp)
             temp = lead;
             win = (p1 > p2) ? "1" : "2";
    System.out.println(win + " " + temp); 


The lead of previous rounds is considered. Please re-read Q carefully, it asks for CUMULATIVE LEAD and not lead at this lead.

Meaning, if at previous round A was at lead of 20, and at next round B got a lead of 40, then actual/cumulative lead of B now is 40-20 =20, and not 40.


According to the last two lines in the below extract from the question it says that the player having maximum lead at the end of any of the round would be the winner.
Please advise if there is any misinterpretation from my end.

In his version, at the end of each round the leader and her current lead are calculated. Once all the rounds are over the player who had the maximum lead at the end of any round in the game is declared the winner.

Read the second table carefully :stuck_out_tongue:

Its the lead of cumulative scores, not current round scores.


Thank You I have solved the question observing the second table.

What I understood is that cumulative lead / score is score of current round + score of next round except for the first round where the scores are copied as it is.

At first I thought that the second table are new set of scores where in the first round the players scored the same score as in round 1 :smiley:

Please let me know if my interpretation of cumulative lead / score is wrong.

If u got AC it means u r right :smiley: