Type: Default 1000ms 256MiB

最大与最小

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Background

给定一个大小为 1 <= n ≤ 1e6 的数组。

有一个大小为 k <= n 的滑动窗口,它从数组的最左边移动到最右边。

你只能在窗口中看到 k 个数字。

每次滑动窗口向右移动一个位置。

Description

以下是一个例子:

该数组为 [1 3 -1 -3 5 3 6 7],k 为 3 。

窗口位置 最小值 最大值
[1 3 -1] -3 5 3 6 7 -1 3
1 [3 -1 -3] 5 3 6 7 -3
1 3 [-1 -3 5] 3 6 7 5
1 3 -1 [-3 5 3] 6 7
1 3 -1 -3 [5 3 6] 7 3 6
1 3 -1 -3 5 [3 6 7] 7

你的任务是确定滑动窗口位于每个位置时,窗口中的最大值和最小值。

Format

Input

输入包含两行。

第一行包含两个整数 n 和 k ,分别代表数组长度和滑动窗口的长度。

第二行有 n 个整数,代表数组的具体数值。

同行数据之间用空格隔开。

Output

输出包含两个。

第一行输出,从左至右,每个位置滑动窗口中的最小值。

第二行输出,从左至右,每个位置滑动窗口中的最大值。

Samples

8 3
1 3 -1 -3 5 3 6 7
-1 -3 -3 -3 3 3
3 3 5 5 6 7

Limitation

1s, 1024KiB for each test case.

2025新生第三次周赛

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
7
Start at
2025-11-23 8:45
End at
2025-11-23 11:45
Duration
3 hour(s)
Host
Partic.
27