Type: Default 1000ms 256MiB

划分

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。 现在,你需要把这 nn 栋楼房划分成若干个连续段,每一个连续段的价值为该段中最矮的楼房的价值。总的价值为每个连续段的价值之和。

你需要求出最大可能的总价值。

输入格式

第一行一个整数 nn,表示楼房数。 第二行 nn 个整数,表示 a1na_{1\dots n}。 第三行 nn 个整数,表示 b1nb_{1\dots n}

输出格式

输出一行一个整数,表示最大的总价值。

样例

Input 1

5
1 2 3 5 4
1 5 3 2 4

Output 1

15

Input 2

5
1 4 3 2 5
-3 4 -10 2 7

Output 2

10

提示说明

Constraints

子任务 nn\le 特殊性质 分值
11 200200 N/A 1515
22 50005000
44 10510^5 aia_i 升序 1010
55 N/A 6060

109bi109-10^9 \le b_i\le 10^9

aa 为一个长度为 nn 的排列


暴力、部分分训练

Not Attended
Status
Done
Rule
IOI
Problem
8
Start at
2024-10-6 14:00
End at
2024-10-6 18:00
Duration
4 hour(s)
Host
Partic.
4