Problem 08A. Kth Largest Element in a Stream ≡

Author:Pavel Mesenev   Time limit:2 sec
Input file:Standard input   Memory limit:256 Mb
Output file:Standard output  

Statement

Values arrive one at a time (n of them), and you are given k. After each arrival, once at least k values have arrived, report the k-th largest value seen so far. Arrivals before the k-th produce no output.

Input format

The first line contains two integers n and k. The second line contains n space-separated integers — the values, in arrival order.

Output format

Print one line per arrival from the k-th onward: the k-th largest value seen so far at that point.

Constraints

1 ≤ k ≤ n ≤ 2 ⋅ 105

 − 109 ≤ value ≤ 109

Sample tests

No. Standard input Standard output
1
6 2
4 5 8 2 3 5
4
5
5
5
5
2
3 1
7 2 9
7
7
9

0.047s 0.017s 16