#C6084. Sliding Window Maximum
Sliding Window Maximum
Sliding Window Maximum
You are given an integer T denoting the number of test cases. For each test case, a sequence of N integers is provided along with an integer L representing the size of a sliding window. Your task is to determine the maximum element in every contiguous subarray (or sliding window) of length L.
Formally, for an array \( a_1, a_2, \ldots, a_N \) and a window length \( L \) (with \( L \le N \)), you need to output a sequence of \( N - L + 1 \) numbers in which the \( i^{th} \) number is defined as:
[ \max_{j=i}^{i+L-1} a_j ]
The answers for each test case should be printed on separate lines. Use efficient algorithms to handle large inputs.
inputFormat
The input is given via stdin
and has the following format:
T N1 L1 a1 a2 ... aN1 N2 L2 a1 a2 ... aN2 ... NT LT a1 a2 ... aNT
Where:
T
is the number of test cases.- For each test case, the first line contains two space-separated integers
N
andL
, whereN
is the number of elements in the array andL
is the fixed window size. - The second line of each test case contains
N
space-separated integers representing the array elements.
outputFormat
For each test case, output one line containing the maximum values of each contiguous subarray of length L
separated by a single space. The output is printed to stdout
.
2
6 3
1 3 5 2 8 7
5 2
4 2 7 3 1
5 5 8 8
4 7 7 3
</p>