Problem2356--1D Pawn

2356: 1D Pawn

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200200 points

Problem Statement

There are NN squares, indexed Square 11, Square 22, …, Square NN, arranged in a row from left to right.
Also, there are KK pieces. The ii-th piece from the left is initially placed on Square A_iAi.
Now, we will perform QQ operations against them. The ii-th operation is as follows:
  • If the L_iLi-th piece from the left is on its rightmost square, do nothing.
  • Otherwise, move the L_iLi-th piece from the left one square right if there is no piece on the next square on the right; if there is, do nothing.
Print the index of the square on which the ii-th piece from the left is after the QQ operations have ended, for each i=1,2,\ldots,Ki=1,2,,K.

Constraints

  • 1\leq K\leq N\leq 2001KN200
  • 1\leq A_1<A_2<\cdots<A_K\leq N1A1<A2<<AKN
  • 1\leq Q\leq 10001Q1000
  • 1\leq L_i\leq K1LiK
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:
NNKKQQA_1A1A_2A2\ldotsA_KAKL_1L1L_2L2\ldotsL_QLQ

Output

Print KK integers in one line, with spaces in between. The ii-th of them should be the index of the square on which the ii-th piece from the left is after the QQ operations have ended.

Sample Input Copy

5 3 5
1 3 4
3 3 1 1 2

Sample Output Copy

2 4 5

HINT

At first, the pieces are on Squares 1133, and 44. The operations are performed against them as follows:

  • The 33-rd piece from the left is on Square 44. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 33-rd piece from the left to Square 55. Now, the pieces are on Squares 1133, and 55.
  • The 33-rd piece from the left is on Square 55. This is the rightmost square, so do nothing. The pieces are still on Squares 1133, and 55.
  • The 11-st piece from the left is on Square 11. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 11-st piece from the left to Square 22. Now, the pieces are on Squares 2233, and 55.
  • The 11-st piece from the left is on Square 22. This is not the rightmost square, but the next square on the right (Square 33) contains a piece, so do nothing. The pieces are still on Squares 2233, and 55.
  • The 22-nd piece from the left is on Square 33. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 22-nd piece from the left to Square 44; Now, the pieces are still on Squares 2244, and 55.

Thus, after the QQ operations have ended, the pieces are on Squares 2244, and 55, so 2244, and 55 should be printed in this order, with spaces in between.

Source/Category