#P2893. [USACO08FEB] Making the Grade G
[USACO08FEB] Making the Grade G
Description
Farmer John wants to renovate a road of length . The original elevation of each segment is , and after repair it becomes , with a cost of . We require the repaired road, that is, the sequence you construct, to be monotone nonincreasing or monotone nondecreasing. Find the minimum total cost .
Input Format
The first line contains an integer .
The next lines each contain an integer .
Output Format
Output a single integer, the minimum cost.
7
1
3
2
4
5
3
9
3
Hint
Constraints: , .
Translated by ChatGPT 5
京公网安备 11011102002149号