SHP - Shuffling Problem
You are given an unordered array with n distinct numbers from 1 to n. You have to perform exactly k swaps and print the lexicographically largest array that can be obtained.
In one swap, you can choose any two distinct indices and swap the elements at those indices.
Input
First line consists of 2 integers n (1 < n ≤ 100000) and k (0 ≤ k ≤ 109).
Next line consists of n integers (a0, a1 ... an-1).
Output
You have to print lexicographically largest array obtained.
Example
Input: 5 2 1 2 4 3 5 Output: 5 4 2 3 1
hide comments
Amitayush Thakur:
2021-02-19 19:01:14
What is the meaning of "lexicographically largest array" ?
|
|
Amitayush Thakur:
2021-02-13 21:28:15
Is it allowed to swap the same pair of indices again and again.
|
|
vineetjai:
2020-09-10 15:31:30
Awesome problem. |
|
kprock41951:
2020-07-15 16:42:38
ah! frustrating!! Last edit: 2020-07-15 19:37:34 |
|
offamitkumar:
2020-06-23 05:55:09
Keep in mind [spoilers removed]. Cost me 5 WA.
|
|
Scape:
2020-06-21 22:30:20
@robosapien, can you give me a case for which my submission fails? Can't figure it out. Am I misunderstanding the problem? Can we swap an index with itself?
|
|
robosapien:
2020-06-21 14:29:31
Thanks. Fixed. |
|
suhash:
2020-06-21 07:59:41
There are cases with n = 1 and k > 0 (which are invalid). Please fix them in the input. |
|
nadstratosfer:
2020-06-19 04:13:18
Please don't set TL below 1s in Classical, it might prevent AC with an efficient solution in a language with interpreter/VM startup lag (albeit in case of this problem Python does pass). |
Added by: | robosapien |
Date: | 2020-06-18 |
Time limit: | 0.100s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |