K-th Smallest Stream
View as PDFYou are given a stream of integers and an integer
.
After each new integer arrives, report the -th smallest value among all numbers seen so far.
If fewer than
numbers have been seen, print
-1 for that step.
Input
The first line contains two integers and
.
The second line contains integers
, where
is the
-th value in the stream.
Output
Print lines. On line
, print:
- the
-th smallest value among
, or
-1if.
Constraints
Example 1
Input
8 3
5 2 7 1 9 3 4 6
Output
-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
Input
5 1
10 -4 8 8 0
Output
10
-4
-4
-4
-4
Comments