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

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

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

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: