#P8239. [AGM 2022 资格赛] 分裂
[AGM 2022 资格赛] 分裂
Problem Description
You have an array of length . You need to split it into non-empty subsegments. The final score is , where is a given constant, is the maximum value in the -th segment, and is the minimum value in the -th segment.
What is the maximum score you can obtain?
Input Format
The first line contains two positive integers .
The next line contains integers representing .
The next line contains integers representing .
Output Format
Output one integer in a single line, representing the answer.
10 3
2 6 10 1 5 9 7 2 1 8
3 1 2
1079
Hint
Constraints
For of the testdata, it is guaranteed that , , and .
Notes
Translated from AGM 2022 Qualification Round K Split。
Translated by ChatGPT 5