atcoder#ABC276C. [ABC276C] Previous Permutation
[ABC276C] Previous Permutation
Score : points
Problem Statement
You are given a permutation of , where .
Assume that is the -th lexicographically smallest among all permutations of . Find the -th lexicographically smallest permutation.
What are permutations?
A permutation of is an arrangement of into a sequence.
What is lexicographical order?
For sequences of length , and , is said to be strictly lexicographically smaller than if and only if there is an integer that satisfies both of the following.
- .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Let be the sought permutation. Print in a single line in this order, separated by spaces.
3
3 1 2
2 3 1
Here are the permutations of in ascending lexicographical order.
Therefore, is the fifth smallest, so the sought permutation, which is the fourth smallest , is .
10
9 8 6 5 10 3 1 2 4 7
9 8 6 5 10 2 7 4 3 1