#P3850. Knuth's Bookshelf
Knuth's Bookshelf
Knuth's Bookshelf
Mr. Knuth has a fine bookshelf with (N) books arranged in order. Recently, he bought (M) new, different books to further his knowledge. He has already marked the positions where each new book should be inserted into his bookshelf and has placed them accordingly. However, due to his age, he has forgotten which book is at some positions. Your task is to simulate the process of inserting these (M) new books one by one into the initial bookshelf and then print the final arrangement of the books.
Initially, the bookshelf contains books labeled (1, 2, \ldots, N) in order. The new books are labeled (N+1, N+2, \ldots, N+M) in the order they are inserted. For each insertion, you are given a position (p) ((1 \le p \le) current number of books + 1). The inserted book takes the (p^{th}) position in the bookshelf, shifting all books from that position onward to the right.
For example, if the current arrangement is: (1\ 2\ 3\ 4) and a new book labeled (5) is inserted at position (2), the new arrangement becomes: (1\ 5\ 2\ 3\ 4).
Help Mr. Knuth by outputting the final sequence of book labels after all insertions.
inputFormat
The first line contains two integers (N) and (M), representing the number of initial books and the number of new books to insert, respectively.
The following (M) lines each contain one integer (p), representing the position at which the corresponding new book (labeled in the insertion order starting from (N+1)) should be inserted. It is guaranteed that (1 \le p \le) (current number of books + 1) at the time of insertion.
outputFormat
Output the final sequence of book labels in the bookshelf (after all insertions), separated by a single space.
sample
4 1
2
1 5 2 3 4