#C13329. Maximum Sliding Window

    ID: 42855 Type: Default 1000ms 256MiB

Maximum Sliding Window

Maximum Sliding Window

You are given a list of integers and an integer k. Your task is to calculate the maximum value for every contiguous subarray (or sliding window) of k elements from the list.

If k is greater than the length of the list, the output should be an empty result.

Mathematical Formulation:

Given a list \( A = [a_1,a_2,\dots,a_n] \) and a window size \( k \), for each index \( 1 \le i \le n-k+1 \) compute:

\[ M_i = \max\{a_i, a_{i+1}, \dots, a_{i+k-1}\} \]

Print the sequence \( M_1, M_2, \dots, M_{n-k+1} \) as the answer.

inputFormat

The input is given via stdin in two lines:

  • The first line contains zero or more space-separated integers representing the elements of the list. If the list is empty, the line will be empty.
  • The second line contains a single integer k representing the window size.

outputFormat

Output to stdout a single line with the maximum value of each sliding window separated by a single space. If there is no valid window, output an empty line.

## sample
1 3 2 5 4 8 6
3
3 5 5 8 8