#C4109. Sliding Window Maximum

    ID: 47611 Type: Default 1000ms 256MiB

Sliding Window Maximum

Sliding Window Maximum

Given an integer array a of size n and an integer k, your task is to compute the maximum value in every contiguous subarray (or sliding window) of size k.

For each valid index i (starting from 0) such that \(0 \leq i \leq n-k\), you need to calculate:

$$max_i = \max_{j=i}^{i+k-1}a_j$$

Process multiple test cases accordingly.

inputFormat

The input is read from standard input and has the following format:

  1. The first line contains an integer T, the number of test cases.
  2. For each test case:
    • The first line contains two integers n and k where n is the number of elements in the array and k is the size of the sliding window.
    • The second line contains n space-separated integers representing the array.

outputFormat

For each test case, output a single line containing the maximum values of all sliding windows of size k. The values in each line should be separated by a single space.

## sample
2
8 3
1 3 -1 -3 5 3 6 7
7 4
4 2 12 11 -5 6 50
3 3 5 5 6 7

12 12 12 50

</p>