Problem 07B. Window Range ≡

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 max(window) − min(window).

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 range 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
4 6 8 8 3 4
2
1 1
5
0
3
5 5
4 4 4 4 4
0

0.159s 0.050s 16