QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 2048 MB Puntuación total: 100

#16079. 轻松爬山

Estadísticas

在我们附近有一座非常美丽的山,从山顶可以俯瞰周围的壮丽景色。然而有一个问题:由于高度差相当大,攀登这座山非常困难。为了让更多的人能够登山并欣赏美景,我们希望让攀登变得更容易。

为此,我们将这座山建模如下:山由 $n$ 个相邻的石堆组成,每个石堆的高度为 $h_i$。因此,相邻石堆的高度差为 $h_{i+1} - h_i$(对于 $1 \le i \le n - 1$)。我们希望所有这些高度差的绝对值都小于或等于某个数 $d$。

我们可以通过增加或减少某些石堆的高度来实现这一目标。第一个石堆(起点)和最后一个石堆(终点)的高度必须保持与初始高度相同。由于增加和移除石头需要付出很多努力,我们希望最小化增加的石头总数与移除的石头总数之和。这个最小值是多少?

输入格式

第一行包含一个正整数:测试用例的数量,最多为 $100$。接下来对于每个测试用例:

  • 一行包含两个整数 $n$($2 \le n \le 100$)和 $d$($0 \le d \le 10^9$):石堆的数量和允许的最大高度差。
  • 一行包含 $n$ 个整数 $h_i$($0 \le h_i \le 10^9$):各个石堆的高度。

输出格式

对于每个测试用例:

  • 输出一行,包含必须增加或移除的最小石头数量,如果无法达到目标,则输出 impossible

样例

输入 1

3
10 2
4 5 10 6 6 9 4 7 9 8
3 1
6 4 0
4 2
3 0 6 3

输出 1

6
impossible
4

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.