Score : $500$ points
You are given a sequence $P = (p_1,p_2,\ldots,p_N)$ that contains $1,2,\ldots,N$ exactly once each.
You may perform the following operations between $0$ and $K$ times in total in any order:
Find the lexicographically smallest $P$ that can be obtained as a result of the operations.
Input is given from Standard Input in the following format:
$N$ $K$ $p_1$ $p_2$ $\ldots$ $p_N$
Print the lexicographically smallest $P$ that can be obtained as a result of the operations, separated by spaces.
5 3 4 5 2 3 1
1 2 3
The following operations make $P$ equal $(1,2,3)$.
There is no way to obtain $P$ lexicographically smaller than $(1,2,3)$, so this is the answer.
3 0 3 2 1
3 2 1
You may be unable to perform operations.
15 10 12 10 7 2 8 11 9 1 6 14 3 15 13 5 4
1 3 4 7 2 8 11 9