2070Easy Dynamic Programming

2070   Easy Dynamic Programming

题目描述

There are N (2 ≤ N ≤ 100,000) poles, each with some heighti meters (1 ≤ heighti ≤ 100). You should connect the tops of each pair of adjacent poles and will incur a penalty cost C × the two poles' height difference for each section of wire where the poles are of different heights (1 ≤ C ≤ 100). The poles, of course, are in a certain sequence and can not be moved.

In addition , if you makes some poles taller you can reduce your penalties, though with some other additional cost. You can add an integer X number of meters to a pole at a cost of X2.

Determine the cheapest combination of growing pole heights and connecting wire so that the cows can get their new and improved service.

输入格式:

Line 1: Two space-separated integers: N and C
       Lines 2 ~ N+1: Line i+1 contains a single integer: heighti .

输出格式:

Line 1: The minimum total amount of money that it will cost to connect all of the poles.

输入样例 复制
5 2
2
3
5
1
4
输出样例 复制
15

说明

1
1
通过提交
时空限制1000ms/128mb
题目来源
评测方式在线评测
题目类型
难        度