You are given an array of integers which is a permutation of the first natural numbers. You can swap any two elements of the array. You can make at most swaps. What is the largest permutation, in numerical order, you can make?
Input Specification
The first line of the input contains two integers, and , the size of the input array and the maximum swaps you can make, respectively. The second line of the input contains a permutation of the first natural numbers.
Output Specification
Print the lexicographically largest permutation you can make with at most swaps.
Constraints
Sample Input 1
5 1
4 2 3 5 1
Sample Output 1
5 2 3 4 1
Explanation of Output for Sample Input 1
You can swap any two numbers in and see the largest permutation is .
Sample Input 2
3 1
2 1 3
Sample Output 2
3 1 2
Explanation of Output for Sample Input 2
With 1 swap we can get , and , out of these is the largest permutation.
Sample Input 3
2 1
2 1
Sample Output 3
2 1
Explanation of Output for Sample Input 3
We can see that is already the largest permutation. So we don't need any swaps.
Original Problem Author: MeHdi_KaZemI8; Problem Resource: HackerRank
Comments