题目描述
You are given an unordered array of unique integers incrementing from $\mbox{1}$. You can swap any two elements a limited number of times. Determine the largest lexicographical value array that can be created by executing no more than the limited number of swaps.
Example
$arr=[1,2,3,4]$
$k=1$
The following arrays can be formed by swapping the $\mbox{I}$ with the other elements:
[2,1,3,4]
[3,2,1,4]
[4,2,3,1]
The highest value of the four (including the original) is $[4,2,3,1]$. If $k\geq2$, we can swap to the highest possible value: $[4,3,2,1]$.
Function Description
Complete the largestPermutation function in the editor below. It must return an array that represents the highest value permutation that can be formed.
largestPermutation has the following parameter(s):
int k: the maximum number of swaps
int arr[n]: an array of integers
Input Format
The first line contains two space-separated integers $n$ and $\boldsymbol{\mbox{k}}$, the length of $\textbf{arr}$ and the maximum swaps that can be performed.
The second line contains $n$ distinct space-separated integers from $\mbox{1}$ to $n$ as $arr\left[i\right]$ where $1\leq ar r[i]\leq n$.
Constraints
$1\leq n\leq10^5$
$1\leq k\leq10^9$
Output Format
Print the lexicographically largest permutation you can make with at most $\boldsymbol{\mbox{k}}$ swaps.
Sample Input 0
STDIN Function
----- --------
5 1 n = 5, k = 1
4 2 3 5 1 arr = [4, 2, 3, 5, 1]
Sample Output 0
5 2 3 4 1
Explanation 0
You can swap any two numbers in $[4,2,3,5,1]$ and see the largest permutation is $[5,2,3,4,1]$
Sample Input 1
3 1
2 1 3
Sample Output 1
3 1 2
Explanation 1
With 1 swap we can get $[1,2,3]$, $[3,1,2]$ and $[2,3,1]$. Of these, $[3,1,2]$ is the largest permutation.
Sample Input 2
2 1
2 1
Sample Output 2
2 1
Explanation 2
We can see that $[2,1]$ is already the largest permutation. We don't make any swaps.
输入格式
见题面
输出格式
见题面