luogu#P4995. 跳跳!
跳跳!
Problem Description
You are a little jumping frog, and you are especially good at jumping around in all kinds of places.
One day, when you went out to play with your friend Little F, you came across a pile of stones with different heights. The height of the -th stone is , and the ground height is . You estimate that the stamina cost to jump from stone to stone is , and the stamina cost to jump from the ground to stone is .
To show Little F your amazing jumping skills, you decide to jump onto each stone exactly once, and finally stop on any stone. Also, the little frog wants to spend as much stamina as possible.
Of course, you are just a little frog. You can only jump, and you do not know how to jump in a way that shows your skills best.
But you are saved! Little F hands you a computer with “AK” written on it, and you can use a computer program to solve this problem. The almighty computer will tell you how to jump.
So please, you little frog who can write code, write this program and take a solid step toward getting NOIp AK!
Input Format
The first line contains a positive integer , the number of stones.
The second line contains positive integers, where the -th integer is the height of the -th stone.
Output Format
Output one positive integer in a single line, the maximum stamina cost you can spend.
2
2 1
5
3
6 3 5
49
Hint
Sample Explanation
For both samples, jumping in the order given in the input is one of the optimal solutions.
Constraints
For , , and all are distinct.
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5