I found my error, it was a dumb mistake.
Read more… (9 words)
I am getting WA for test cases 4 and 6
import java.util.*;class Main{public static void main(String args[]){Scanner sc = new Scanner(System.in);int n = sc.nextInt();int h = sc.nextInt();int crane[] = new int[n];for(int i =0;i<n;i++){crane[i] = sc.nextInt();}int current_pos = 0;boolean has_box = false;while(true){int input = sc.nextInt();if(current_pos != 0 && input == 1){current_pos--;}if(current_pos != n-1 && input ==2){current_pos++;}if(has_box == false && input == 3){has_box = true;if(crane[current_pos]!=0)crane[current_pos] = crane[current_pos] - 1;}if(has_box == true&& input==4&&crane[current_pos]<h){has_box = false;crane[current_pos] = crane[current_pos] + 1;}if(input==0){break;}}for(int i =0;i<n;i++){System.out.print(crane[i]+" ");}}}