PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000148. Theo dõi đoàn tàu (Train Tracking)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Theo dõi đoàn tàu (Train Tracking)

Train Tracking

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

A train has NN carriages numbered 00 through N−1N-1. Carriage ii has an integer identifier cic_i. The same train is observed twice in the same carriage order. Determine the minimum identifier in every group of exactly KK consecutive carriages.

For every starting index ll between 00 and N−KN-K, define

ansl=min⁡(cl,cl+1,…,cl+K−1).ans_l=\min(c_l,c_{l+1},\ldots,c_{l+K-1}).

Output these minima in increasing order of ll.

PHOJ adaptation notice: The original problem uses a two-pass grader, 5,500 persistent integer notebook slots, a limit of 25 million get/set calls, and a required helpBessie callback. This standard-I/O PHOJ package checks the numerical minima but does not automatically enforce the original grader's restricted persistent state. A separate grader kit is supplied for faithful testing.

Input

  • The first line contains two integers NN and KK.
  • The second line contains NN integers c0,c1,…,cN−1c_0,c_1,\ldots,c_{N-1} in carriage order.

Output

Print N−K+1N-K+1 lines. Line l+1l+1 contains the minimum identifier among carriages ll through l+K−1l+K-1.

Subtasks

  • Subtask 1 (20 points): 1≤K≤N≤20001\le K\le N\le 2000; 0≤ci≤1090\le c_i\le 10^9 for every 0≤i<N0\le i<N.
  • Subtask 2 (30 points): 1≤K≤N≤1000001\le K\le N\le 100000; 0≤ci≤1090\le c_i\le 10^9 for every 0≤i<N0\le i<N.
  • Subtask 3 (50 points): 1≤K≤N≤10000001\le K\le N\le 1000000; 0≤ci≤1090\le c_i\le 10^9 for every 0≤i<N0\le i<N.

Examples

Input

10 3
5 7 9 2 0 1 7 4 3 6

Output

5
2
0
0
0
1
3
3

Explanation

Here N=10N=10, K=3K=3. The eight consecutive windows are [5,7,9], [7,9,2], [9,2,0], [2,0,1], [0,1,7], [1,7,4], [7,4,3], and [4,3,6]. Their minima are 5,2,0,0,0,1,3,35,2,0,0,0,1,3,3, respectively, matching the eight output lines.