SDE Path

Sliding Window Maximum

Hard

Sliding Window Maximum

Find the maximum element in every window of size K as it slides across an array.

Input format

The first line contains N and K (1 ≤ K ≤ N). The second line contains N integers.

Output format

Print the maximum of every window of size K as it slides left to right, space-separated.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
8 3
1 3 -1 -3 5 3 6 7
Expected output
3 3 5 5 6 7
Example 2
Input
1 1
5
Expected output
5