Telephone Line
Time limit1sMemory limit128 MB
Raise each pole to height at least its original, paying squared increase plus C times adjacent height gaps, and minimize the total.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Math
- Solved
- No attempts yet
Problem
Jaehyeon wants to install a telephone line through a village.
The village has utility poles standing in a row; the initial height of the -th pole is . Jaehyeon may first raise each pole by any amount (heights can never be lowered), and then runs the telephone line through poles in order. Let () be the final height of pole after raising.
- Raising cost: raising a pole by costs . So pole contributes .
- Line cost: connecting two adjacent poles and costs .
Find the minimum total cost to raise the poles and connect the whole line. The total cost is the sum of all raising costs plus the sum of all line costs.
Input
The first line contains the number of poles and the cost coefficient , separated by a space. (, )
Each of the next lines contains the initial height of one pole. ()
Output
Print the minimum total cost to connect the entire telephone line on a single line.
Hint
Consider poles with and initial heights . Raising them to yields a total cost of , and no smaller cost is possible.