Skip to content
UPEEC

Sliding Window Maximum

Hard#queue#deque#sliding-window· solved by 0 · time limit 2.0 s

For every window of kk consecutive elements, print its maximum. Use a deque to get O(n)O(n) overall.

Input

nn, then nn integers, then kk.

Output

n−k+1n-k+1 maxima.

Constraints

1≤k≤n≤2×1051 \le k \le n \le 2 \times 10^5

Sample 1

Input

8
1 3 -1 -3 5 3 6 7
3

Output

3 3 5 5 6 7

Sign in or join free to run and submit your solution.