F. [USACO08FEB] Making the Grade G

    Type: RemoteJudge 1000ms 128MiB

[USACO08FEB] Making the Grade G

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目描述

农夫约翰想改造一条长度为 NN 的路,原来的路的每一段海拔是 AiA_i,修理后是 BiB_i,花费 AiBi|A_i - B_i|。我们要求修好的路,即你构造的 BiB_i,是单调不升或者单调不降的。求最小花费 i=1NAiBi\sum_{i=1}^{N} |A_i - B_i|

输入格式

第一行包含一个整数 NN

接下来 NN 行,每行包含一个整数 AiA_i

输出格式

一行一个整数,表示最小花费。

7
1
3
2
4
5
3
9

3

提示

数据范围为 1N2000,0Ai1091\le N\le 2000, 0\le A_i\le 10^9

2025CSP-J DP【李】

Not Claimed
Status
Done
Problem
28
Open Since
2025-10-14 0:00
Deadline
2025-10-21 23:59
Extension
24 hour(s)