← 返回 amazon 的题目列表Simplified Top-K
类型:online_judge
Given an integer array nums of length n and an integer k (1 <= k <= n), return the largest k elements in the array, sorted in descending order.
Requirements:
Duplicates may exist.
Target time complexity is at most O(n log k).
Extra space is allowed; state the space complexity.
Input Format
Line 1: two integers n and k
Line 2: n integers representing nums
Output Format
One line: k integers — the largest k elements in descending order
Constraints
1 <= n <= 2 * 10^5
-10^9 <= nums[i] <= 10^9
Sample Tests
Input:
5 2
3 2 1 5 6
Output:
6 5
Input:
6 3
3 2 3 1 2 4
Output:
4 3 3
Example
Input
5 2
3 2 1 5 6
Output
6 5