#C7286. Maximum of Subarrays

    ID: 51140 Type: Default 1000ms 256MiB

Maximum of Subarrays

Maximum of Subarrays

Given an array of integers and an integer (k), your task is to find the maximum element in every contiguous subarray of size (k). More formally, for an array (A) of length (n), you need to output an array (B) such that (B_i = \max{A_i, A_{i+1}, \dots, A_{i+k-1}}) for each valid (i). If (n = 0) or (k > n), output nothing. This problem can be efficiently solved using the sliding window technique and a double-ended queue (deque).

inputFormat

The input is read from standard input (stdin). 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 subarray window. The second line contains (n) space-separated integers representing the elements of the array.

outputFormat

Output to standard output (stdout) the maximum element of each contiguous subarray of size (k) as a sequence of space-separated integers. If no subarray exists (e.g., when (k > n) or (n = 0)), output nothing.## sample

8 3
1 3 1 2 0 5 8 6
3 3 2 5 8 8