LogiQuest

206. First Negative in Every Window

EasyQueueSliding Window

For each window of size k, print the first negative number in it, or 0 if there is none.

Input format

Line 1: n k Line 2: n integers

Output format

n − k + 1 values.

Example 1

Input

8 3
12 -1 -7 8 -15 30 16 28

Output

-1 -1 -7 -15 -15 0

Example 2

Input

5 2
-8 2 3 -6 10

Output

-8 0 -6 -6

Constraints

1 ≤ k ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.

Loading the MyLoginn IDE…