QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 512 MB Total points: 100

#356. 通信

الإحصائيات

$n$ 个排成一列的哨站要进行通信。第 $i$ 个哨站的频段为 $a_i$。

每个哨站 $i$ 需要选择以下二者之一:

  1. 直接连接到控制中心,代价为 $W$;
  2. 连接到前面的某个哨站 $j$($j< i$),代价为 $\lvert a_i - a_j \rvert$。

每个哨站只能被后面的至多一个哨站连接。

请你求出最小可能的代价和。

输入格式

第 $1$ 行两个自然数 $n, W$,分别表示哨站个数和连接到控制中心的代价;

第 $2$ 行 $n$ 个由空格分隔的自然数 $a_1, a_2, \dots , a_n$ 依次表示每个哨站的频段。

输出格式

输出 $1$ 行 $1$ 个自然数表示答案。

样例数据

样例 1 输入

6 7
8 4 6 1 3 0

样例 1 输出

23

样例 1 解释

如果用 $0$ 表示控制中心,最优方案中每个哨站向前连接的哨站依次为 $0,0,1,2,3,4$。

样例 2 输入

8 4
0 4 2 6 1 5 3 7

样例 2 输出

18

子任务

对于所有数据,$1\le n \le 1000,0\le w,a_i\le 10^9$。

  • 对于 $10\%$ 的数据,$n\le 10$;
  • 对于另外 $10\%$ 的数据,$n\le 20$;
  • 对于另外 $20\%$ 的数据,$n\le 50,W\le 5,a_i\le 4$;
  • 对于另外 $20\%$ 的数据,$n\le 100$;
  • 对于另外 $20\%$ 的数据,$n\le 300$;
  • 对于余下 $20\%$ 的数据,无特殊限制。
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.