You are not logged in. Please login at www.codechef.com to post your questions!

×

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;
}

asked 30 May '17, 00:51

jjtomar's gravatar image

2★jjtomar
15910
accept rate: 4%


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.

link

answered 30 May '17, 01:05

abdullah768's gravatar image

6★abdullah768
2.4k420
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) vijju123 ♦♦5★
2

Got that. I think i might've just skimmed past that table. ;P

(30 May '17, 01:11) jjtomar2★

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.

link

answered 30 May '17, 01:01

vijju123's gravatar image

5★vijju123 ♦♦
15.1k11857
accept rate: 18%

@vijju123 u may close this post as well :P

(30 May '17, 01:12) jjtomar2★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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