
https://www.acmicpc.net/problem/23882
import java.io.*;
public class Bronze1_23882_알고리즘수업선택정렬2 {
static int[] arr;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
int N = Integer.parseInt(input[0]);
int K = Integer.parseInt(input[1]);
String[] arrStr = br.readLine().split(" ");
arr = new int[N];
for(int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(arrStr[i]);
}
boolean isSuccess = selectionSort(K);
if(isSuccess) {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < arr.length; i++) {
sb.append(arr[i] + " ");
}
System.out.println(sb.toString().trim());
} else {
System.out.println(-1);
}
}
static boolean selectionSort(int K) {
int count = 0;
int point = 0;
for(int i = arr.length-1; i >= 0; i--) {
point = i;
for(int j = 0; j < i; j++) {
if(arr[point] < arr[j]) {
point = j;
}
}
if(i != point) {
count++;
int tmp = arr[i];
arr[i] = arr[point];
arr[point] = tmp;
if(count == K) return true;
}
}
return false;
}
}