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

×

Help me debugging TLG

why am I getting the wrong answer although my output is correct?! here's the Q:https://www.codechef.com/problems/TLG my code(c):

#include <stdio.h>
#include <stdlib.h>
int r;
int main()
{


    scanf("%d",&r);
    int sc[r][4],i,max1=0,max2=0;
    for(i=0;i<r;i++)
    {


        scanf("%d",&sc[i][0]);scanf("%d",&sc[i][1]);
        if(sc[i][0]>sc[i][1])
        {
        sc[i][2]=(sc[i][0]-sc[i][1]);
        sc[i][3]=0;}
        else
            {
            sc[i][3]=(sc[i][1]-sc[i][0]);
            sc[i][2]=0;}


    }
     max1=sc[0][2];
     max2=sc[0][3];
    for (i=0;i<r;i++)
    {

        if(sc[i][2]>max1)
           {
              max1=sc[i][2];
           }
         if(sc[i][3]>max2)
           {
              max2=sc[i][3];
           }
    }
    if(max1>max2)
        {printf("\n%d",1);printf(" %d",max1);}
    else
        {printf("\n%d",2);printf(" %d",max2);}

    return 0;
}

asked 14 Jun '17, 02:51

nigel1997's gravatar image

1★nigel1997
1
accept rate: 0%

converted to question 14 Jun '17, 10:32

vijju123's gravatar image

4★vijju123 ♦♦
15.2k11859


Look at the table in the question carefully!!

Lead in each round is the CUMULATIVE sum of leads of that round and leads of previous round. Meaning, lead is to be taken from TOTAL SCORE instead of that particular round's score. Look here-

 Round           Player 1(TOTAL SCORE)   Player 2(Total score)   Winner      Lead
      1               140                82                  Player 1     58
      2               229               216                  Player 1     13
      3               319               326                  Player 2      7
      4               431               432                  Player 2      1
      5               519               522                  Player 2      3

Look at the lead calculation. It is not the lead obtained from that round, but sum of lead of previous round+sum of lead of that round. I advise looking at the 2 tables given in Q again. Hope this helps ^^

link

answered 14 Jun '17, 10:37

vijju123's gravatar image

4★vijju123 ♦♦
15.2k11859
accept rate: 18%

what u have done is took d differrence of scores in each round and calculate d max.differrence printed accordingly.....bt what actually u have to do is to take d difference of a particular round by calculating score till dat round for both players and then u should take d differrence...and find the max.diff and print accordingly...i have modified ur code and also submited jst now which gave me an AC .....here is ur modified code : https://www.codechef.com/viewsolution/14251106 !! hope dis clears ur doubt !! happy coding :)

link

answered 14 Jun '17, 12:04

msd_007's gravatar image

1★msd_007
3178
accept rate: 5%

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:

×2,698
×1,056
×123

question asked: 14 Jun '17, 02:51

question was seen: 324 times

last updated: 14 Jun '17, 12:04