#P5331. [SNOI2019] 通信

[SNOI2019] 通信

Description

There are nn sentry stations arranged in a line. The frequency band of station ii is aia_i.

Each station ii needs to choose one of the following two options:

  1. Connect directly to the control center, with a cost of WW.
  2. Connect to some previous station jj (j<ij<i), with a cost of aiaj|a_i-a_j|.

Each station can be connected by at most one later station.

Please find the minimum possible total cost.

Input Format

The first line contains two non-negative integers n,Wn, W, representing the number of sentry stations and the cost to connect to the control center.

The second line contains nn non-negative integers a1,a2,,ana_1, a_2, \ldots, a_n separated by spaces, representing the frequency band of each station in order.

Output Format

Output one line containing one non-negative integer, representing the answer.

6 7
8 4 6 1 3 0
23
8 4
0 4 2 6 1 5 3 7
18

Hint

For all testdata, 1n10001 \leq n \leq 1000, 0W,ai1090 \leq W, a_i \leq 10^9.

For 10%10\% of the testdata, n10n \leq 10.

For another 10%10\% of the testdata, n20n \leq 20.

For another 20%20\% of the testdata, n50n \leq 50, W5W \leq 5, ai4a_i \leq 4.

For another 20%20\% of the testdata, n100n \leq 100.

For another 20%20\% of the testdata, n300n \leq 300.

For the remaining 20%20\% of the testdata, there are no special constraints.

Translated by ChatGPT 5