fork download
  1. import java.io.*;
  2. import java.util.*;
  3. class crane
  4. {
  5. public static void main(String[] args)throws IOException
  6. {
  7. Scanner sc=new Scanner(System.in);
  8. int n=sc.nextInt();int h=sc.nextInt();
  9. int a[]=new int[n];
  10. int hook=0,pick=0;
  11. for(int i=0;i<n;i++)
  12. {
  13. a[i]=sc.nextInt();
  14. }
  15. do
  16. {
  17. int com=sc.nextInt();
  18. if(com==0)break;
  19. if(com==1 && hook!=0)
  20. {
  21. hook--;
  22. }
  23. if(com==2 && hook!=n-1)
  24. {
  25. hook++;
  26. }
  27. if(com==3 && pick==0 && a[hook]>0)
  28. {
  29. a[hook]--;pick=1;
  30. }
  31. if(com==4 && pick==1 && a[hook]<h)
  32. {
  33. a[hook]++;pick=0;
  34. }
  35. }while(true);
  36. for(int i=0;i<n;i++)
  37. System.out.print(a[i]);
  38. }
  39. }
Success #stdin #stdout 0.06s 711680KB
stdin
3 5
2 5 2
3 2 4 2 2 2 1 4 1 1 1 1 0
stdout
152