题目描述
Farmer John's cows aregetting restless about their poor telephone service; they want FJ to replacethe old telephone wire with new, more efficient wire. The new wiring willutilize N (2 ≤ N ≤ 100,000) already-installed telephone poles, each with someheighti meters (1 ≤ heighti ≤ 100). The new wire will connect the tops of eachpair of adjacent poles and will incur a penalty cost C × the two poles' heightdifference 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 bemoved.
Farmer John figuresthat if he makes some poles taller he can reduce his penalties, though withsome other additional cost. He can add an integer X number of meters to a poleat a cost of X2.
Help Farmer Johndetermine the cheapest combination of growing pole heights and connecting wireso that the cows can get their new and improved service.
给出若干棵树的高度,你可以进行一种操作:把某棵树增高h,花费为h*h。
操作完成后连线,两棵树间花费为高度差*定值c。
求两种花费加和最小值。
输入输出格式
输入格式:
* Line 1: Twospace-separated integers: N and C
* Lines 2..N+1: Linei+1 contains a single integer: heighti
输出格式:
* Line 1: The minimumtotal amount of money that it will cost Farmer John to attach the new telephonewire.
输入输出样例
输入样例#1: 复制
输出样例#1: 复制