Problem6515-- ABC234 —— D - Prefix K-th Max

6515: ABC234 —— D - Prefix K-th Max

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

Given are a permutation $P=(P_1,P_2,\ldots,P_N)$ of $(1,2,\ldots,N)$ and a positive integer $K$.
For each $i=K,K+1,\ldots,N$, find the following.
  • The $K$-th greatest value among the first $i$ terms of $P$.

Input

Input is given from Standard Input in the following format:
$N\ K$
$P_1\ P_2\ \ldots\ P_N$

Output

For each $i=K, K+1, \ldots, N$, in this order, print the specified value in Problem Statement, separated by newlines.

Constraints

$1≤K≤N≤5×10^5$
$(P_1,P_2,\ldots,P_N)$ is a permutation of $(1,2,\ldots,N)$.
All values in input are integers.

Sample 1 Input

3 2
1 2 3

Sample 1 Output

1
2
The $(K=)\ 2$-nd greatest value among the first $2$ terms of $P, (P_1,P_2)=(1,2)$, is $1$.
The $(K=)\ 2$-nd greatest value among the first $3$ terms of $P, (P_1,P_2,P_3)=(1,2,3)$, is $2$.

Sample 2 Input

11 5
3 7 2 5 11 6 1 9 8 10 4

Sample 2 Output

2
3
3
5
6
7
7

Source/Category

 AtCoder_ABC 100.234.ABC234