P28972 [洛谷] [SNOI2019] Communication
省选
题目描述

Problem Description

There are $n$ outposts arranged in a line that need to communicate. The frequency band of the $i$-th outpost is $a_i$.

Each outpost $i$ needs to choose one of the following options:

  1. Connect directly to the control center, with a cost of $W$;
  2. Connect to a previous outpost $j$ ($j < i$), with a cost of $|a_i - a_j|$.

Each outpost can be connected to by at most one subsequent outpost.

Please find the minimum possible total cost.

Input Format

The first line contains two natural numbers $n$ and $W$, representing the number of outposts and the cost of connecting to the control center, respectively.

The second line contains $n$ natural numbers separated by spaces, $a_1, a_2, \ldots, a_n$, representing the frequency bands of each outpost in order.

Output Format

Output one line with one natural number, representing the answer.

Sample Input and Output

Sample Input #1

6 7
8 4 6 1 3 0

Sample Output #1

23

Sample Input #2

8 4
0 4 2 6 1 5 3 7

Sample Output #2

18

Notes/Hints

For all data, $1 \leq n \leq 1000$, $0 \leq W, a_i \leq 10^9$.

For $10\%$ of the data, $n \leq 10$;

For another $10\%$ of the data, $n \leq 20$;

For another $20\%$ of the data, $n \leq 50$, $W \leq 5$, $a_i \leq 4$;

For another $20\%$ of the data, $n \leq 100$;

For another $20\%$ of the data, $n \leq 300$;

For the remaining $20\%$ of the data, there are no special restrictions.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
6 7 8 4 6 1 3 0
样例输出
23