Problem 07A. Sliding Window Maximum ≡

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

Statement

You are given an array a0, a1, …, an − 1 of integers and a window size k. For every contiguous window of size k, output the maximum value in that window. There are n − k + 1 windows in total.

Input format

The first line contains two integers n and k. The second line contains n space-separated integers a0… an − 1.

Output format

Print n − k + 1 space-separated integers: the maximum of each window, in order.

Constraints

1 ≤ k ≤ n ≤ 2 ⋅ 105

 − 109 ≤ ai ≤ 109

Sample tests

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

0.035s 0.009s 18