#P2251. Sliding Window Minimum

    ID: 15529 Type: Default 1000ms 256MiB

Sliding Window Minimum

Sliding Window Minimum

You are given a sequence of N products where each product is assigned an integer quality score \(A_i\). To evaluate the quality over intervals, you need to compute the sliding window minimum sequence \(Q\). For a given window size \(M\), the sliding window minimum is defined as:

\[ Q_i = \min\{A_i, A_{i+1}, \ldots, A_{i+M-1}\} \quad \text{for} \quad 1 \le i \le N-M+1. \]

Your task is to compute the \(Q\) sequence for the given \(A\) array.

inputFormat

The first line contains two integers \(N\) and \(M\) separated by a space, where \(N\) is the number of products and \(M\) is the size of the sliding window. The second line contains \(N\) integers \(A_1, A_2, \ldots, A_N\) representing the quality scores of the products.

outputFormat

Output the sliding window minimum sequence \(Q\) as space-separated integers in one line.

sample

5 3
1 3 2 5 4
1 2 2