400. K-th Largest in a Stream
MediumHeap
Numbers arrive one by one. After each arrival print the k-th largest so far, or -1 if fewer than k numbers have arrived.
Input format
Line 1: n k Line 2: n integers
Output format
n answers.
Example 1
Input
6 3 4 5 8 2 3 10
Output
-1 -1 4 4 4 5
Example 2
Input
3 1 5 1 9
Output
5 5 9
Constraints
1 ≤ k ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.
Loading the MyLoginn IDE…