import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.PriorityQueue; import java.util.Comparator; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] params = br.readLine().split(" "); int n = Integer.parseInt(params[0]), k = Integer.parseInt(params[1]); String[] arr = br.readLine().split(" "); PriorityQueue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a); for(int i = 0; i < n; i++){ if(maxHeap.size() < k){ maxHeap.offer(Integer.parseInt(arr[i])); }else{ int cur = Integer.parseInt(arr[i]); if(maxHeap.peek() > cur){ maxHeap.poll(); maxHeap.offer(cur); } } } StringBuilder res = new StringBuilder(); while(!maxHeap.isEmpty()) res.append(maxHeap.poll() + " "); System.out.println(res.toString().trim()); } }