From one to en (3) P69756


Statement
 

pdf   zip

Write a program that prints all the permutations of {1,,n}\{ 1, \dots, n \} with kk inversions, for a given nn and kk. An inversion is a pair of elements xx and yy such that x>yx > y and such that xx appears before yy in the permutation.

Input

Input consists of two natural numbers nn and kk, such that n1n \ge 1 and 0kn(n1)/20 \le k \le n(n - 1)/2.

Output

Print all the permutations of {1,,n}\{ 1, \dots, n \} with kk inversions.

Information about the checker

You can print the solutions to this exercise in any order.

Hint

Here, a very simple algorithm may be too slow.

Public test cases
  • Input

    5 2
    

    Output

    (1,2,4,5,3)
    (1,2,5,3,4)
    (1,3,2,5,4)
    (1,3,4,2,5)
    (1,4,2,3,5)
    (2,1,3,5,4)
    (2,1,4,3,5)
    (2,3,1,4,5)
    (3,1,2,4,5)
    
  • Input

    10 45
    

    Output

    (10,9,8,7,6,5,4,3,2,1)
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python