Stable Permutation
Time limit3sMemory limit256 MB
Find the k-th lexicographically smallest permutation of length n whose inversion count is exactly half of all pairs, or report NO if none exists.
- Level
Hard8 of 10
- Topics
- Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
A permutation of length is a sequence where each and whenever . For a pair of positions , the pair is an inversion if . A permutation is stable if reversing it leaves the number of inversions unchanged. Find the -th stable permutation of length in lexicographic order.
Input
The only line contains two integers and (, ).
Output
If such a permutation exists, print YES on the first line and the numbers on the second line. Otherwise, print NO.
Hint
There are 6 stable permutations of length 4: , , , , , .