K Largest Elements
Easyjavapythonccppjavascript
Given an integer array and K, find the K largest values.
Input Format
The first line contains two integers N and K. The second line contains N space-separated integers.
Output Format
Print the K largest values in decreasing order, separated by single spaces.
Example 1
Input
6 3 3 1 5 12 2 11
Output
12 11 5
Explanation: The three largest values are 12, 11 and 5.
- 1 <= K <= N <= 100000
- -1000000000 <= A[i] <= 1000000000