#P2808. [JOI2014 预选赛] 小笼包
[JOI2014 预选赛] 小笼包
Description
The xiaolongbao set that JOI ordered consists of xiaolongbao with different fillings. The xiaolongbao are arranged in a row at equal intervals, numbered to . The distance between the -th and -th xiaolongbao is the absolute value .
JOI eats the xiaolongbao in some order. Initially, the deliciousness of every xiaolongbao is . When eating the -th xiaolongbao, soup splashes outward; all xiaolongbao whose distance from the -th xiaolongbao is at most are splashed, and each splashed xiaolongbao has its deliciousness increased by . That is, when eating the -th xiaolongbao, if the and -th xiaolongbao has not yet been eaten, then the deliciousness of the -th xiaolongbao increases by .

JOI will choose the eating order to maximize the total deliciousness of the xiaolongbao eaten.
Input Format
The input consists of three lines.
The first line contains an integer .
The second line contains integers , separated by spaces.
The third line contains integers , separated by spaces.
Output Format
Output one line: the maximum possible total deliciousness of the xiaolongbao eaten by JOI.
5
1 0 1 1 2
0 2 6 3 4
20
10
5 2 7 2 6 5 3 5 3 6
8 7 8 4 0 6 0 10 10 0
237
Hint
Explanation for Sample : If JOI eats in the order $5\rightarrow 3\rightarrow 1\rightarrow 2\rightarrow 4$, the total deliciousness is . It can be proven that no eating order yields a total exceeding .
This problem is Problem of the 2014 Japanese Olympiad in Informatics (JOI) Preliminary Round.
Translated by ChatGPT 5
京公网安备 11011102002149号