#P11538. Chessboard Pieces Movement
Chessboard Pieces Movement
Chessboard Pieces Movement
You are given a chessboard with n cells numbered from \(1\) to \(n\) (from left to right), where \(n \le 1000\). Initially, there are m pieces placed on the board, with \(m \le n\). The pieces are numbered from \(1\) to \(m\), and the \(i\)-th piece is placed at cell \(p_i\). It is guaranteed that no two pieces share the same cell.
You will be given \(k\) operations. In each operation, you need to choose a piece (by its number) and attempt to move it to the first empty cell on its right. Formally, if a piece is currently at cell \(x\), then it should be moved to cell \(y\) where \(y > x\) is the smallest number such that cell \(y\) is empty. If there is no such cell (i.e. the piece is already at the rightmost occupied region), then the operation is illegal, and the board remains unchanged.
For each operation, output the new cell number of the moved piece if the move is legal; otherwise, output error!
.
Note: Any mathematical formulas in this problem must be formatted in LaTeX.
inputFormat
The first line contains three integers \(n\), \(m\), and \(k\) \((1 \le m \le n \le 1000)\) representing the number of cells, the number of pieces, and the number of operations, respectively.
The second line contains \(m\) distinct integers \(p_1, p_2, \dots, p_m\) \((1 \le p_i \le n)\) where \(p_i\) is the starting cell of the \(i\)-th piece.
The following \(k\) lines each contain a single integer representing the number of the piece to be moved in that operation.
outputFormat
For each of the \(k\) operations, output a single line. If the operation is legal, output the new position of the piece after its move; otherwise, output error!
.
sample
5 2 4
2 4
1
2
1
1
3
5
4
error!
</p>