← 返回 microsoft 的题目列表Return the Top K Largest Numbers
类型:online_judge
Given an integer array nums and an integer k, return the largest k elements in the array, sorted in descending order.
Duplicate values are allowed and must be treated as separate elements.
Input Format
First line: two integers n and k, the array length and the number of elements to return.
Second line: n integers representing nums.
Output Format
Print the k largest elements in descending order, separated by spaces.
Example 1
Input:
6 3
3 2 1 5 6 4
Output:
6 5 4
Example 2
Input:
9 4
3 2 3 1 2 4 5 5 6
Output:
6 5 5 4
Constraints
1 <= n <= 10^5
1 <= k <= n
-10^9 <= nums[i] <= 10^9
Example
Input
6 3
3 2 1 5 6 4
Output
6 5 4