# Problem Code: ZCO14001

Only one subtask doesn’t pass! Can anyone find my error in the code.
My Code:

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

int main(void) {
long long int i,temp,max,a[100000000],b[100000000],n,height,locat=0,box=0;
scanf("%lld%lld",&n,&height);
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
for(i=0;i<100000000;i++)
{
scanf("%lli",&b[i]);
if(b[i]==0)
{
max=i;
break;
}
}
for(i=0;i<=max;i++)
{
if(b[i]==0)
{
for(temp=0;temp<n;temp++)
printf("%lld ",a[temp]);
}else
if(b[i]==1)
{
if(locat<=0)
{
//printf("Can't Go Left\n");
}else
{
locat--;
}
}else
if(b[i]==2)
{
if(locat>=max)
{
//printf("Can't Go Front\n");
}else
{
locat++;
}
}else
if(b[i]==3)
{
if(a[locat]<=0||box==1)
{
//printf("Can't Lift The Box\n");
}else
{
a[locat]--;
box=1;
}
}else
if(b[i]==4)
{
if(a[locat]>=height||box==0)
{
// printf("Can't Drop The Box\n");
}else
{
a[locat]++;
box=0;
}
}
}
return 0;
}
``````

It dosen’t pass the 5th test case!

@pratik_2003

The mistake which you are making in your code is as follows:

In the line: if(locat>=max)

The variable max is counting the number of commands (which may differ from the number of boxes). Therefore in the following example your code won’t work and it will give you a weird answer.

3 5

2 5 2

3 2 4 2 2 2 2 4 1 1 1 1 0

This is simply because the location will be greater than n - 1. I won’t tell that what you have to do because you can figure that out.

1 Like

Thanks dude… It really helped for me!

You’re welcome.

//