LEADGAME - Editorial

Prerequisites:- None

Problem:- You’re given N rounds of Billiard, with the ith containing Si and Ti, The score of Player1 and Player2.
After each round calculate the total score of both players and find the leader of the game and its current lead.
Find the player who achieved the maximum lead in one of the given rounds and the maximum lead achieved.

Explanation :-

After each round : -
Update the total point of player 1 and 2,( S = S+Si , T = T+Ti )
Find the winner of the round according to the points, the player with maximum points wins the round.
Check the lead gained by the winner. If the lead is greater than any of the previous round lead, store it as the maximum lead with the player name (1 or 2).

Solution : -
c++

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin>>n;
    int player= 0,lead = 0;
    int s = 0,t = 0;
    for(int i = 0; i < n; i++){
        int si,ti;
        cin>>si>>ti;
        s = s+si;
        t = t+ti;
        if(s>t && s-t>lead){
            lead = s-t;
            player = 1;
        }
        else if(t-s>lead)
        {
            lead = t-s;
            player = 2;
        }
   }
    cout<<player<<" "<<lead;
	

}

20
774 233 player 1 : with lead 541
112 234 player 2 : with lead 122
694 426 player 1 : with lead 268
866 352 player 1 : with lead 514
516 33 player 1: with lead 483
497 545 player 2: with lead 48
87 309 player 2 : with lead 222
407 413 player 2 : with lead 6
628 737 player 2 : with lead 109
307 628 player 2 : with lead 321
306 344 player 2 : with lead 38
323 426 player 2: with lead 103
414 590 player 2: with lead 176
401 714 player 2: with lead 313
797 703 player 1: with lead 90
128 571 player 2: with lead 443
287 591 player 2: with lead 304
804 980 player 2 : with lead 176
16 22 player 2: with lead 6
683 532 player 1 : with lead 160

to this test data by the system according to the above calculation player 1 is the winner with lead 541 but, the expected result is 1 1684

It is invalid expected result i guess.

Same error as this. Still not fixed.