#P5331. [SNOI2019] 通信

[SNOI2019] 通信

Problem 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 ∣ai−aj∣|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, 1≤n≤10001 \leq n \leq 1000, 0≤W,ai≤1090 \leq W, a_i \leq 10^9.

For 10%10\% of the testdata, n≤10n \leq 10.

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

For another 20%20\% of the testdata, n≤50n \leq 50, W≤5W \leq 5, ai≤4a_i \leq 4.

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

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

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

Translated by ChatGPT 5