johnny and the beanstalk

the code chef is giving wrong answer for my code…but it is giving desired output on my compiler
please check whats wrong…here is my code http://www.codechef.com/viewsolution/4368650

I saw your whole code your logic is correct but you havent considered the case when the no leaves given in array are greater than s. Here’s your corrected solution
#include<stdio.h>
int main()
{
int t,i;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
int n,j,l,s=1;
scanf("%d",&n);
for(j=1;j<=n;j++)
{
scanf("%d",&l);
if(l<=s)
{
s=s-l;
s=s2;
}
else if(l>s)
{
s=2
n;
}

    }
    if(s==0)
        printf("Yes\n");
    else
        printf("No\n");

}
return 0;

}
the case where i have written if(l>s) s=2n;
you can assign some larger value to s.

1 Like

actually the code is being shown on 2 lines but I hope you understood this

you missed out on the cases when leaves are more than possible.

thanks…:slight_smile:

//