K-th Smallest Stream
You are given a stream of n integers and an integer k.
After each new integer arrives, report the k-th smallest value among all numbers seen so far.
If fewer than k numbers have been seen, print -1 for that step.
Input
The first line contains two integers n and k.
The second line contains n integers a1,a2,…,an, where ai is the i-th value in the stream.
Output
Print n lines. On line i, print:
- the k-th smallest value among a1,a2,…,ai, or
-1if i<k.
Constraints
- 1≤k≤n≤2⋅105
- −109≤ai≤109
Example 1
8 3
5 2 7 1 9 3 4 6
-1
-1
7
5
5
3
3
3
Explanation
After the first 3 values (5, 2, 7), the 3rd smallest is 7.
After 6 values (5, 2, 7, 1, 9, 3), sorted order is 1, 2, 3, 5, 7, 9, so the 3rd smallest is 3.
Example 2
5 1
10 -4 8 8 0
10
-4
-4
-4
-4
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.