#P3672. K-th Permutation with Given Inversion Count
K-th Permutation with Given Inversion Count
K-th Permutation with Given Inversion Count
Given three natural numbers n, k, and x, find the k-th smallest permutation in lexicographical order among all permutations of the set {1, 2, ..., n} that have exactly x inversion pairs. An inversion pair is defined as a pair of indices (i, j) such that i < j and ai > aj. It is guaranteed that such a permutation exists.
Note:
- Comparisons between permutations are done in lexicographical order.
- The permutation is a rearrangement of 1 through n.
- The k-th smallest is counted starting from 1.
inputFormat
The input consists of a single line containing three integers n, k, and x separated by spaces.
Constraints: n is a natural number, and 0 ≤ x ≤ n*(n-1)/2. It is guaranteed that there exists at least one permutation of {1,2,…,n} with exactly x inversions, and that the k-th such permutation exists.
outputFormat
Output the required permutation as a sequence of n space-separated integers in one line.
sample
3 1 1
1 3 2