#P8239. [AGM 2022 资格赛] 分裂

[AGM 2022 资格赛] 分裂

Problem Description

You have an array aa of length nn. You need to split it into KK non-empty subsegments. The final score is i=1Kmxibimnibi\sum_{i=1}^K mx_i^{b_i}-mn_i^{b_i}, where bib_i is a given constant, mximx_i is the maximum value in the ii-th segment, and mnimn_i is the minimum value in the ii-th segment.

What is the maximum score you can obtain?

Input Format

The first line contains two positive integers n,Kn, K.

The next line contains nn integers representing aia_i.

The next line contains KK integers representing bib_i.

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 100%100\% of the testdata, it is guaranteed that 1Kn50001 \leq K \leq n \leq 5000, 1ai1051 \leq a_i \leq 10^5, and 1bi31 \leq b_i \leq 3.

Notes

Translated from AGM 2022 Qualification Round K Split

Translated by ChatGPT 5