#P10736. [SEERC 2020] Archeologists
[SEERC 2020] Archeologists
Problem Description
You are playing a treasure-hunting game. There are cells numbered from to . Each time you dig down by one layer in cell , you gain a value of .
You must ensure that for any two adjacent cells, the difference between their digging depths is at most (note that cells and can be dug down by at most one layer). Please maximize the total value.
Input Format
The first line contains an integer .
The next line contains integers .
Output Format
Output the maximum total value.
5
1 3 -4 2 1
8
4
1 1 -2 3
5
5
-1 -3 0 -5 -4
0
Hint
Explanation for Sample 1:

Translated by ChatGPT 5