atcoder#ABC257B. [ABC257B] 1D Pawn
[ABC257B] 1D Pawn
Score : points
Problem Statement
There are squares, indexed Square , Square , …, Square , arranged in a row from left to right. Also, there are pieces. The -th piece from the left is initially placed on Square . Now, we will perform operations against them. The -th operation is as follows:
- If the -th piece from the left is on its rightmost square, do nothing.
- Otherwise, move the -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 -th piece from the left is after the operations have ended, for each .
Constraints
- $1\leq A_1
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print integers in one line, with spaces in between. The -th of them should be the index of the square on which the -th piece from the left is after the operations have ended.
5 3 5
1 3 4
3 3 1 1 2
2 4 5
At first, the pieces are on Squares , , and . The operations are performed against them as follows:
- The -rd piece from the left is on Square . This is not the rightmost square, and the next square on the right does not contain a piece, so move the -rd piece from the left to Square . Now, the pieces are on Squares , , and .
- The -rd piece from the left is on Square . This is the rightmost square, so do nothing. The pieces are still on Squares , , and .
- The -st piece from the left is on Square . This is not the rightmost square, and the next square on the right does not contain a piece, so move the -st piece from the left to Square . Now, the pieces are on Squares , , and .
- The -st piece from the left is on Square . This is not the rightmost square, but the next square on the right (Square ) contains a piece, so do nothing. The pieces are still on Squares , , and .
- The -nd piece from the left is on Square . This is not the rightmost square, and the next square on the right does not contain a piece, so move the -nd piece from the left to Square ; Now, the pieces are still on Squares , , and .
Thus, after the operations have ended, the pieces are on Squares , , and , so , , and should be printed in this order, with spaces in between.
2 2 2
1 2
1 2
1 2
10 6 9
1 3 5 7 8 9
1 2 3 4 5 6 5 6 2
2 5 6 7 9 10