Max Sum
题号:NC200602
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Hery has two arrays a and k with n integers. Let to be the weight of interval [L, R]. For each position i (1 ≤ i ≤ n), hery defines interval [L, R] as a wonderful interval of i if:

• 1 ≤ L ≤ R ≤ n


.
For each i from 1 to n, s_i
is the max weight of all wonderful intervals of i. Hery wants to know the
value of: .

输入描述:

The first line contains two integers n.
The second line has an array k with n integers.
The third line has an array a with n integers.

输出描述:

Output the value of .
示例1

输入

复制
5
1 2 3 4 4
-5 1 2 3 -4

输出

复制
16
示例2

输入

复制
3
0 0 0
1 2 3

输出

复制
6
示例3

输入

复制
3
2 2 2
1 2 3

输出

复制
18
示例4

输入

复制
5
1 2 3 4 5
-1 -2 -3 -4 -5

输出

复制
-15