# What is wrong with this code for TLG problem?

The link to problem : TLG

My code :

``````/* PROB - TLG */

#include <stdio.h>

int main(void) {
scanf("%d\n", &t);
while(t--)
{
scanf("%d\n", &s1);
scanf("%d\n", &s2);
if(diff==-1)
{
if(s1>s2)
{
win = 1;
}
else
{
win = 2;
}
}
else
{
if(s1>s2)
{
diff = s1-s2;
{
win = 1;
}
}
else
{
diff = s2-s1;
{
win = 2;
}
}
}
}
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.

2 Likes

@vijju123 u may close this post as well