Rough Sorting
시간 제한2초메모리 제한512 MB
순열과 K가 주어질 때, 인접 교환을 최소 횟수로 사용해 역순 쌍이 K개 이하인 배열을 만들고, 답이 여러 개면 사전순으로 가장 작은 배열을 구한다.
문제
For skilled programmers, it is very easy to implement a sorting function. Moreover, they often avoid full sorting to reduce computation time if it is not necessary. Here, we consider "rough sorting" which sorts an array except for some pairs of elements. More formally, we define an array is "-roughly sorted" if an array is sorted except that at most pairs are in reversed order. For example, 1 3 2 4 is 1-roughly sorted because is only the reversed pair. In the same way, 1 4 2 3 is 2-roughly sorted because and are reversed.
Considering rough sorting by exchanging adjacent elements repeatedly, you need less number of swaps than full sorting. For example, 4 1 2 3 needs three exchanges for full sorting, but you only need to exchange once for 2-rough sorting.
Given an array and an integer , your task is to find the result of the -rough sorting with a minimum number of exchanges. If there are several possible results, you should output the lexicographically minimum result. Here, the lexicographical order is defined by the order of the first different elements.
입력
The input consists of a single test case in the following format.
$N$ $K$
$x_{1}$
$\vdots$
$x_{N}$
The first line contains two integers and . The integer is the number of the elements of the array (). The integer gives how many reversed pairs are allowed (). Each of the following lines gives the element of the array. The array consists of the permutation of to , therefore and () are satisfied.
출력
The output should contain lines. The -th line should be the -th element of the result of the -rough sorting. If there are several possible results, you should output the minimum result with the lexicographical order.
힌트
In the last example, the input array is already sorted, which means the input is already a 3-roughly sorted array and no swapping is needed.