The Lead Game not working.Help.

include <stdio.h>

int cmp (int a,int b)
{
return (
(int
)a-(int)b);
}

int main(void)
{
int t,a,b,c,e,f,g,h;
scanf ("%d",&t);
int d [t][2],i [t][2],j [t];
for (c=0;c <t;c++)
{
scanf ("%d %d",&a,&b);
if (a <=0 || b <=0 || a>1000 || b>1000)
{
abort ();
}
d [c][0]=a;d [c][1]=b;i [c][0]=0;i [c][1]=0;
i [c][0]=i [c][0]+d [c][0];
i [c][1]=i [c][1]+d [c][1];
}
for (c=0;c <t;c++)
{
j [c]=i [c] [0]-i[c] [1];
}
qsort (j,t,sizeof (int),cmp);
e=j [t-1];g=abs (e);
f=j [0];h=abs (f);
if (g>h)
{
printf (“1 %d”,g);
}
else if (g==0 && f==0)
{
abort ();
}
else
{
printf (“2 %d”,h);
}

return 0;

}

Why am i getting Wrong Answer.Please help.

hi kriskhundu , if u can generate a url of your code on ideone then it would be helpful for us to debug

The question asks you to find the max lead on the basis of total score till a round. And, the total score of a round is the cumulative sum of all the scores till that round, including it.

Looking at your


[1], it seems like you are storing the cumulative score in the array $i[t][2]$. But there's a problem in the implementation. Change this

     i [c][0] = i [c][0] + d [c][0];
     i [c][1] = i [c][1] + d [c][1];

To this

     i [c][0] = i [c-1][0] + d [c][0];
     i [c][1] = i [c-1][1] + d [c][1];

Also, take care of the case when $c = 0$ ($c-1$ will be $-1$ in that case), and then your code will be fine.

The reason that your code gives a right answer in the sample test case is that the max lead in it happens in the first round itself, so there is no need of a cumulative score. But this may not happen always, giving a wrong answer in the other cases.

  [1]: https://www.codechef.com/viewsolution/14672084

Thank you Mr Lifesaver :slight_smile:

1 Like

Well, you can show your gratitude by accepting the answer.

r=[]
s=[]
for t in range(int(input())):
a,b=map(int,raw_input().split())
if a>b:
c=a-b
r.append©
s.append(1)
elif b>a:
c=b-a
r.append©
s.append(2)
e=[list(l) for l in zip(r,s)]
print e
q=max(e)
print q[1],q[0]

my code for lead game in python… wrong answer help needed.

//