 # getting wrong ans in THE LEAD GAME .HELP!!!!

,

cannot find what is wrong with this code of question link text . workng for most of the test cases i tried on my pc still getting wrong answer with codechef compiler . help !!

``````#include<stdio.h>

int main()

{

int i,j,k,l,first,x=0,a,p=0,q=0,diff=0,n,b;

for(i=0;i<=n;i++)
{
if(i==0)
{
scanf("%d",&n);
}
else
{
scanf("%d",&a);
scanf("%d",&b);
p=p+a;
q=q+b;
if(p>q)
{
if(diff<(p-q))
{
diff=p-q;
x=1;
}
}
else
{
if(diff<(q-p))
{
diff=q-p;
x=2;
}
}
}
}
printf("%d %d",x,diff);
return 0;
}
``````

The slight error with your code is that you have initialized diff to 0. So if a’s and b’s which you will get are equal then a-b or b-a will never be greater than diff hence your x value will never update. So it will give you a wrong answer. I submitted your code which gave the correct answer :

http://www.codechef.com/viewsolution/3648654

2 Likes

Don`t know why are you doing p=p+a; and q=q+b; as the scores of each round are calculated separated according to new rules(as in question)... You can simply use p=a and q=b and there is no problem whatsoever if you don`t use p and q…as a-b or b-a have no use further in next upcoming rounds