From one to en (3)

Write a program that prints all the permutations of {1, …, n} with k
inversions, for a given n and k. An inversion is a pair of elements x
and y such that x > y and such that x appears before y in the
permutation.

Input

Input consists of two natural numbers n and k, such that n ≥ 1 and
0 ≤ k ≤ n(n − 1)/2.

Output

Print all the permutations of {1, …, n} with k 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.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:39:59.304Z

© Jutge.org, 2006–2026.
https://jutge.org
