#P1389. 一个关于序列的游戏

    ID: 384 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp福建省历届夏令营

一个关于序列的游戏

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:

  1. For every pair of adjacent elements, the absolute difference is 11.
  2. 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 [1,2,3,4,3][1,2,3,4,3], [1,2][1,2], [3,2][3,2], and [3][3] 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 NN, the length of the sequence.

The second line contains NN integers V1,V2VNV_1, V_2 \cdots V_N, where VLV_L is the score for deleting a segment of length LL.

The third line contains NN integers A1,A2ANA_1, A_2 \cdots A_N, 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 10%10\% of the testdata, N3N \le 3.
  • For 40%40\% of the testdata, N10N \le 10.
  • For 70%70\% of the testdata, N70N \le 70.
  • For 100%100\% of the testdata, 1N1501 \le N \le 150, 10000Vi10000-10000 \le V_i \le 10000, 0Ai10000000000 \le A_i \le 1000000000. No value AiA_i appears more than 1414 times.

Translated by ChatGPT 5