#P1389. 一个关于序列的游戏
一个关于序列的游戏
Description
There is a sequence. You may delete, any number of times, a contiguous segment that meets the rules below. Each deletion yields a score equal to the length of that segment.
The segment must satisfy:
- For every pair of adjacent elements, the absolute difference is .
- If an element is not the leftmost or rightmost element of the segment, then it cannot be strictly smaller than both of its immediate neighbors.
All of , , , and satisfy the rules.
After removing a segment, the elements to the left and right of that segment become adjacent.
Your task is: for the given sequence, compute the maximum possible total score.
Input Format
The first line contains an integer , the length of the sequence.
The second line contains integers , where is the score for deleting a segment of length .
The third line contains integers , the elements of the initial sequence.
Output Format
Output a single integer: the maximum total score that can be obtained.
6
-100 5 6 10 0 0
3 1 2 3 4 10
11
Hint
Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , , . No value appears more than times.
Translated by ChatGPT 5
京公网安备 11011102002149号