After some apple picking, many of the apple pickers decide to go canoeing at Emerald lake before the lake freezes over. It has docks numbered from left to right, each being able to dock exactly 1 canoe. canoers, numbered , decide to all go canoeing there. Each canoer chooses a distinct dock to dock their canoe, and canoer 1 just so happens to start at dock number 1. Each day, all canoers depart on their canoes for a ride, and their number dictates the order in which they return back to the docks (canoer number 1 arrives back first, canoer number 2 arrives second, etc.). Each canoer will always try to return to the dock they departed from, however if it is already taken, then they will go to the dock to the right. They will continue right until they find an open dock, at which they will dock there. If they reach dock without having any place to dock, then they continue on from dock 1 and keep moving right until they come across a dock that is free.
Each day, all canoers depart from the dock they left their canoes on from the day before, and return back following the process described above. However, canoer 1 is causing some trouble, and decides to instead always dock 1 spot to the right of theirs (if they departed from dock number , then they go to dock number 1). Write a program to output the order of the canoers after days of this process.
Input Specifications
The first line will contain 2 spaced integers, and , which are the number of canoers/docks and the number of days respectively.
The next line will contain integers from 1 to (in some order), denoting the initial order of canoers at the start of day 1, each separated by a single space.
Note that dock number 1 will always be canoer number 1 at the beginning of day 1.
Output Specifications
On a single line, output the order of the canoers from left to right at the end of the -th day, each integer separated by a single space.
Subtasks
Subtask 1 [50%]
Subtask 2 [30%]
Subtask 3 [20%]
No additional constraints
Sample Input 1
5 4
1 5 2 4 3
Sample Output 1
2 3 4 5 1
Explanation for Sample Output 1
During the first day (after departing),
Canoer 1 arrives first and decides to dock 1 to the right, at dock number 2. x 1 x x x
Canoer 2, 3, and 4 can dock in the same places they departed. x 1 2 4 3
Canoer 5 arrives to find that their dock has been taken. Canoer 5 then checks docks 3, 4, and 5, but they are all taken. Canoer 5 then checks dock number 1, finding it is empty and docks there. 5 1 2 3 4
Thus, the 1st day ends and the 2nd day begins with the order of 5 1 2 4 3
.
During the second day (after departing),
Canoer 1 first arrives and docks 1 to the right, at dock number 3. x x 1 x x
Canoer 2 attempts to dock at the same dock they departed from, but since it is taken, they go right until they find one, and so they dock at dock 4. x x 1 2 x
Canoer 3 can dock on the same dock they departed from. x x 1 2 3
Canoer 4 attempts to dock at the same dock they departed from, but since it is taken, they go right until they find one, but all are taken. Canoer 4 then starts to search from dock number 1, and finds it is empty and docks there. 4 x 1 2 3
Canoer 5 attempts to dock at the same dock they departed from, but since it is taken, they go right until they find one, and so they dock at dock 2. 4 5 1 2 3
Day 2 ends with the order of 4 5 1 2 3
.
Day 3 ends with the order of 3 4 5 1 2
.
And finally, day 4 ends with the order of 2 3 4 5 1
.
Sample Input 2
10 6
1 8 3 9 5 7 10 4 2 6
Sample Output 2
5 6 7 8 9 10 1 3 2 4
Explanation for Sample Output 2
The 6 days are as follows:
End of day 1: 10 1 3 8 5 7 9 4 2 6
End of day 2: 9 10 1 3 5 7 8 4 2 6
End of day 3: 8 9 10 1 3 5 7 4 2 6
End of day 4: 7 8 9 10 1 3 5 4 2 6
End of day 5: 6 7 8 9 10 1 3 4 2 5
End of day 6: 5 6 7 8 9 10 1 3 2 4
Comments