397. K Largest Elements
EasyHeap
Print the k largest elements in descending order.
Input format
Line 1: n k Line 2: n integers
Output format
k values.
Example 1
Input
6 3 1 23 12 9 30 2
Output
30 23 12
Example 2
Input
3 3 5 5 5
Output
5 5 5
Constraints
1 ≤ k ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…