What is wrong with this code for TLG problem?

,

The link to problem : TLG

My code :

/* PROB - TLG */
 
#include <stdio.h>
 
int main(void) {
	// your code goes here
	int t,win=1,diff=-1,lead=0,s1,s2;
	scanf("%d\n", &t);
	while(t--)
	{
	    scanf("%d\n", &s1);
	    scanf("%d\n", &s2);
	    if(diff==-1)
	    {
	        if(s1>s2)
	        {
	            lead = diff = s1-s2;
	            win = 1;
	        }
	        else
	        {
	            lead = diff = s2-s1;
	            win = 2;
	        }
	    }
	    else
	    {
	        if(s1>s2)
	        {
	            diff = s1-s2;
	            if(diff>lead)
	            {
	                lead=diff;
	                win = 1;
	            }
	        }
	        else
	        {
	            diff = s2-s1;
	            if(diff>lead)
	            {
	                win = 2;
	                lead = diff;
	            }
	        }
	    }
	}
	printf("%d %d\n", win, lead);
	return 0;
}

The scores of previous round accumulate!!

Meaning, Take this example-

2
140 82
89 155

In first case, player 1 leads by 58 points. In second round, ALTHOUGH player 2 achieves a lead of 66, we have to see the accumulated scores. So lead for round 2 is (82+155)-(140+89)=8 .

I got AC when i followed this logic. Refer to the table given in problem statement for more details.

1 Like

Your code finds the difference for each round individually but the question requires you to find the difference between the cumulative scores till that round.

2 Likes

Even i got stuck on that part while solving it XD. A good lesson on reading problem statement minutely haha.

1 Like

Got that. I think i might’ve just skimmed past that table. :stuck_out_tongue_winking_eye:

2 Likes

@vijju123 u may close this post as well :stuck_out_tongue: