The Lead Game
Practice this coding question on Coding Gurukul.
Problem statement
A two-player tournament records the points earned in each round. The announcer wants to recognise the player who held the largest cumulative lead at the end of any round. This is different from winning a single round or finishing with the highest final total. You are implementing the scoreboard history calculation used to select that award. Your task Add each round’s points to the two running totals. After every round, calculate the absolute difference between the cumulative totals and identify the player ahead. Track the greatest lead observed. Print the player number, 1 or 2, followed by that lead. If the same maximum lead occurs again, keep the player recorded at its earliest occurrence. Important details Compare cumulative totals, not just the current round’s scores. At least one round ends with unequal totals. A tied round does not create a positive lead. Worked example For rounds (10,2), (0,20), (20,0), cumulative scores are (10,2), (10,22), (30,22). Player 2 held the greatest lead, 12, after round two. Print 2 12.
Input format
First line: n. Next n lines: points1 points2.
Output format
Print winnerNumber maximumLead.
Constraints
1 <= n <= 10000; round points are 0..1000; some cumulative lead is positive.
Sample input
3 10 2 0 20 20 0
Sample output
2 12
Sign in to run or submit a solution in C++, Java or Python.