Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/navbat-oyna-maksimumi

Sliding window maximum

Medium 1000 ms 128 MB 64%
Share

An array $a$ of $n$ integers and a positive integer $k$ are given. A window of length $k$ moves one position at a time from the beginning of the array to the end: first it covers $a_{1}, \dots, a_{k}$, then $a_{2}, \dots, a_{k+1}$, and so on. Find the largest element in every position of the window.

Consecutive positions of a window of fixed length over the array cells, the largest element highlighted in each

Input

The first line contains two positive integers: $n$ and $k$. The second line contains $n$ integers $a_{i}$ separated by spaces.

Output

One line with $n - k + 1$ integers separated by spaces — the largest element in each position of the window.

Note

$1 \le k \le n \le 2 * 10^{5}$
$-10^{9} \le a_{i} \le 10^{9}$

Examples

Input #1
8 3
1 3 -1 -3 5 3 6 7
Output #1
3 3 5 5 6 7
Input #2
3 3
4 2 9
Output #2
9

Sign in to submit a solution

Signing up is free and takes a minute.