Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.*;
- import java.util.StringTokenizer;
- public class Main
- {
- static class FastReader
- {
- BufferedReader br;
- StringTokenizer st;
- public FastReader()
- {
- br = new BufferedReader(new
- InputStreamReader(System.in));
- }
- String next()
- {
- while (st == null || !st.hasMoreElements())
- {
- try
- {
- st = new StringTokenizer(br.readLine());
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
- int nextInt()
- {
- return Integer.parseInt(next());
- }
- long nextLong()
- {
- return Long.parseLong(next());
- }
- double nextDouble()
- {
- return Double.parseDouble(next());
- }
- String nextLine()
- {
- String str = "";
- try
- {
- str = br.readLine();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- return str;
- }
- }
- public static void main(String[] args)
- {
- FastReader in=new FastReader();
- int N = in.nextInt();
- int H = in.nextInt();
- long[] boxes = new long[N];
- for(int i = 0; i< N;i++)boxes[i] = in.nextLong();
- int c = 0, pos = 0;
- boolean hold = false;
- while((c = in.nextInt()) != 0){
- if(c == 1)pos = Math.max(0, pos-1);
- if(c == 2)pos = Math.min(N-1, pos+1);
- if(c == 3){
- if(boxes[pos] >0 && !hold){
- boxes[pos]--;
- hold = true;
- }
- }
- if(c == 4){
- if(boxes[pos] < H && hold){
- boxes[pos]++;
- hold = false;
- }
- }
- }
- for(int i = 0; i< N; i++)System.out.print(boxes[i] + " ");
- }
- }
Add Comment
Please, Sign In to add comment