K-th Smallest Stream

View as PDF

Submit solution


Points: 100
Time limit: 1.0s
Memory limit: 977M

Problem type

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 a_1, a_2, \dots, a_n, where a_i is the i-th value in the stream.

Output

Print n lines. On line i, print:

  • the k-th smallest value among a_1, a_2, \dots, a_i, or
  • -1 if i < k.

Constraints

  • 1 \le k \le n \le 2 \cdot 10^5
  • -10^9 \le a_i \le 10^9

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

There are no comments at the moment.