Help me debugging TLG

help
debug
wa

#1

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

#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*[0]);scanf("%d",&sc*[1]);
        if(sc*[0]>sc*[1])
        {
        sc*[2]=(sc*[0]-sc*[1]);
        sc*[3]=0;}
        else
            {
            sc*[3]=(sc*[1]-sc*[0]);
            sc*[2]=0;}


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

        if(sc*[2]>max1)
           {
              max1=sc*[2];
           }
         if(sc*[3]>max2)
           {
              max2=sc*[3];
           }
    }
    if(max1>max2)
        {printf("

%d",1);printf(" %d",max1);}
else
{printf("
%d",2);printf(" %d",max2);}

    return 0;
}

#2

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 ^^


#3

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 :slight_smile: