#C4109. Sliding Window Maximum
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:
- The first line contains an integer
T
, the number of test cases. - For each test case:
- The first line contains two integers
n
andk
wheren
is the number of elements in the array andk
is the size of the sliding window. - The second line contains
n
space-separated integers representing the array.
- The first line contains two integers
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.
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>