A Permutation Problem 2

View as PDF

Submit solution

Points: 12
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Given 2 integers N and K, find the lexicographically largest permutation of 1, 2, \dots, N such that it takes exactly K swaps (between any two elements) to most efficiently sort it.

We define the most efficient sorting of an array of integers as one where the number of swaps is minimized.

The answer is guaranteed to exist.

Input Specification

The first and only line will contain 2 integers, N (1 \le N \le 10^6), K (0 \le K \le 10^6).

Output Specification

On one line, output the lexicographically greatest array that satisfies the conditions outlined in the problem statement.

Sample Input

4 3

Sample Output

4 3 1 2

Comments


  • -3
    Togohogo1  commented on Feb. 16, 2020, 4:27 p.m.

    Is it possible to not MLE in py3


    • 2
      Riolku  commented on Feb. 16, 2020, 5:27 p.m.

      If you need a hint, try to use \mathcal O(1) memory.

      P.S. damn it c beat me to it.


    • 3
      c  commented on Feb. 16, 2020, 5:14 p.m. edited

      Yes