×

What is wrong with this code for TLG problem?

 0 The link to problem : TLG My code : /* PROB - TLG */ #include 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; }  asked 30 May '17, 00:51 2★jjtomar 159●10 accept rate: 4%

 2 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. answered 30 May '17, 01:05 2.4k●4●20 accept rate: 17% 1 Even i got stuck on that part while solving it XD. A good lesson on reading problem statement minutely haha. (30 May '17, 01:09) 2 Got that. I think i might've just skimmed past that table. ;P (30 May '17, 01:11) jjtomar2★
 1 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. answered 30 May '17, 01:01 15.1k●1●18●57 accept rate: 18% @vijju123 u may close this post as well :P (30 May '17, 01:12) jjtomar2★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,042
×60

question asked: 30 May '17, 00:51

question was seen: 310 times

last updated: 30 May '17, 01:12