https://www.codechef.com/ZCOPRAC/problems/ZCO14001

// why is this wrong for the question in the link anyone explain pls
#include
using namespace std;

int main() {
int n;
int h;

cin>>n>>h;

int b[n];

for(int i=0;i<n;i++){
    cin>>b[i];
    if(b[i]>h){
        return 0;
    }
}

int c;


int i=0;
int m=b[0];
int r=0;
int y=0;
while(i<n){
    cin>>c;
    
    if(c==0){
        break;
    }
    
    
    if(c==1&y!=0){
       m = b[y-1];
       y--;
    }
    
    
    if(c==2 & y!=n-1){
       m=b[y+1];
       y++;
    }
    
    
    if(c==3&m!=0&r!=1){
        b[y]=b[y]-1;
        r=1;
    }
    
    
    if(c==4 & m<h&r!=0){
        b[y]=b[y]+1;
        r=0;
    }
    
}

for(int i=0;i<n;i++){
    cout<<b[i]<<" ";
}

return 0;

}

I see you solved this problem

1 Like