#P7852. Lexicographically Maximum Permutation with Limited Swaps
Lexicographically Maximum Permutation with Limited Swaps
Lexicographically Maximum Permutation with Limited Swaps
Given two integers \(n\) and \(m\), output a permutation \(P = [p_1, p_2, \dots, p_n]\) of \(\{1,2,\dots, n\}\) that satisfies the following condition:
By performing no more than \(m\) swap operations on \(P\), it is possible to transform \(P\) into the lexicographically smallest permutation \( [1,2,\dots,n] \). Among all such permutations, you are required to output one which is lexicographically maximum.
A swap operation is defined as exchanging the positions of any two elements in the permutation. If there are multiple answers, output any one of them.
Note: The minimum number of swaps needed to sort a permutation is \(n - c\), where \(c\) is the number of disjoint cycles in its cycle decomposition. Thus, the condition is equivalent to requiring \(n - c \le m\), i.e. \(c \ge n-m\).
inputFormat
The input consists of a single line containing two space‑separated integers \(n\) and \(m\) \( (1 \le n \le 10^5,\ 0 \le m \le n-1) \).
outputFormat
Output \(n\) integers representing the permutation \(P\). The numbers should be separated by a single space. The output permutation must be such that it can be transformed into \([1,2,\dots,n]\) using at most \(m\) swap operations, and among all such valid permutations, it is lexicographically maximum.
sample
5 0
1 2 3 4 5