Problem 900
Reveal Cards In Increasing Order
Medium · 20 pts · Array, Queue, Simulation, Sorting
Problem
Each card in a deck shows a distinct number. Cards are revealed like this: reveal the top card and remove it, then move the next top card to the bottom, and repeat until no cards remain. Arrange the deck so that the cards are revealed in increasing order, and print it from top to bottom. Simulate the process on positions 0..N-1 with a queue to learn which position is revealed k-th, and put the k-th smallest card there.
Input
The first line contains N. The second line contains the N distinct card values.
Output
Print the arranged deck from top to bottom, separated by spaces.
Constraints
1 <= N <= 1000; 1 <= value <= 10^6; values are distinct
Example input
7 17 13 11 2 3 5 7
Example output
2 13 3 11 5 17 7
Explanation
For cards 17 13 11 2 3 5 7, the deck 2 13 3 11 5 17 7 reveals 2, moves 13 to the bottom, reveals 3, moves 11 down, and so on, revealing 2 3 5 7 11 13 17 in order.