QOJ.ac

QOJ

Límite de tiempo: 15.0 s Límite de memoria: 256 MB Puntuación total: 100 Hackeable ✓

#11016. 血压游戏

Estadísticas

我们可以将过山车的路径看作一个由 $n$ 个不同高度的转折点组成的列表,表示为大小为 $n$ 的数组 $\{a_1, a_2, a_3, \dots, a_n\}$。Gugulu 在过山车游戏后的最终血压计算为数组中 $n-1$ 对相邻数字之差的绝对值之和,即 $\sum_{i=1}^{n-1} |a_i - a_{i+1}|$。

Gugulu 决定将一组 $m$ 个额外的转折点以任意顺序加入到这条路径中。然而,考虑到原始路径的距离现实,他可以在数组中任意两个原始元素之间的位置(以及头部之前、尾部之后)最多添加一个转折点。Gugulu 希望尽可能提高他的血压,他想知道当他分别添加 $\{1, 2, 3, \dots, m\}$ 个额外的过山车转折点时,他的血压最高能达到多少。

输入格式

输入的第一行包含测试用例的数量 $T$ ($1 \le T \le 1000$)。接下来是 $T$ 个测试用例。 每个测试用例的第一行包含两个整数 $n$ ($1 \le n \le 600$) 和 $m$ ($1 \le m \le n + 1$)。 第二行包含 $n$ 个整数 $\{a_1, a_2, a_3, \dots, a_n\}$ ($1 \le a_i \le 10^9$),表示 $n$ 个原始过山车转折点。 第三行包含 $m$ 个整数 $\{b_1, b_2, b_3, \dots, b_m\}$ ($1 \le b_i \le 10^9$),表示要添加的 $m$ 个额外过山车转折点。保证这两个数组中的所有 $n+m$ 个整数两两不同。 $n > 100$ 的测试用例最多有 10 个。

输出格式

对于每个测试用例,输出三行。第一行包含 “Case #x:”,其中 $x$ 是测试用例编号(从 1 开始)。第二行包含 $m$ 个整数,表示如果他分别添加了 $\{1, 2, 3, \dots, m\}$ 个额外过山车转折点,Gugulu 的血压最高能达到多少。第三行包含 $n+m$ 个整数,表示如果他添加了所有 $m$ 个额外转折点,最终过山车路径的高度。如果有多种方案,输出其中任意一种即可。

样例

样例输入 1

6
2 3
5 11
10 3 1
4 1
1 2 3 4
5
4 2
1 2 3 4
5 6
4 5
1 2 3 4
5 6 7 8 9
4 4
10 50 3 6
1 9 23 5
4 2
10 50 3 6
9 23

样例输出 1

Case #1:
16 22 27
10 5 1 11 3
Case #2:
9
1 5 2 3 4
Case #3:
11 15
1 6 2 5 3 4
Case #4:
17 27 33 38 39
5 1 9 2 8 3 7 4 6
Case #5:
124 142 147 150
5 10 1 50 3 23 6 9
Case #6:
124 127
10 50 3 23 6 9

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.