Link to the Problem: https://www.codechef.com/ZCOPRAC/problems/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!