QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 2048 MB Points totaux : 100

#5656. Vittorio 玩乐高积木

Statistiques

Vittorio 正在玩他的新乐高得宝(LEGO Duplo)积木。所有的积木形状均为底面为 $2 \times 2$ 的正方形、高度为 $1$ 的长方体。它们可以在三维空间中排列以搭建结构,前提是必须满足以下规则:

  1. 任意两块积木不能重叠,但它们可以在面上接触。
  2. 每块积木的顶点坐标必须为整数(因此积木与坐标轴对齐),且所有顶点的 $z$ 坐标必须非负。
  3. 每块积木的底面必须平行于地面(即平面 $z = 0$)。
  4. 任何不接触地面的积木,其底面必须与另一块积木的顶面在正面积区域内接触(当这种情况发生时,两块积木会因为小凸起而相互固定)。

例如,这是一个合法的结构:

Vittorio 想要搭建一个包含紫色积木的结构,这些紫色积木位于以下 $n$ 个位置:$(x_1, 0, h), (x_2, 0, h), \dots, (x_n, 0, h)$ —— 这些是它们底面中心的坐标;注意所有这些积木的 $y$ 坐标均为 $0$,且 $z$ 坐标均为 $h$。Vittorio 将使用其他颜色的额外积木来支撑这些紫色积木。他只愿意将积木放置在底面中心 $y$ 坐标为 $0$ 的位置。请问最少需要多少块额外积木?

可以证明,合法的构造总是存在的。

输入格式

第一行包含两个整数 $n$ 和 $h$ ($1 \le n \le 300, 0 \le h \le 10^9$),分别表示紫色积木的数量及其共同的 $z$ 坐标。

第二行包含 $n$ 个整数 $x_1, x_2, \dots, x_n$ ($1 \le x_i \le 10^9, x_i < x_{i+1}$),表示紫色积木的 $x$ 坐标(底面中心),按递增顺序给出。

输出格式

输出所需额外积木的最小数量。

样例

样例输入 1

4 0
2 7 11 13

样例输出 1

0

说明 1

所有的紫色积木都位于地面上,因此不需要额外的积木。

样例输入 2

4 1
2 7 11 13

样例输出 2

3

说明 2

Vittorio 必须在紫色积木下方放置支撑积木,他可以使用一块积木同时支撑第三块和第四块紫色积木。例如,他可以在位置 $(3, 0, 0), (7, 0, 0)$ 和 $(12, 0, 0)$ 放置额外积木。可以证明,使用少于 $3$ 块额外积木是不可能完成合法构造的。

样例输入 3

4 100
2 7 11 13

样例输出 3

107

样例输入 4

4 3
2 5 8 11

样例输出 4

8

说明 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.