Abaka.aiOA #2
Maximize the Power
估计中等可在线判题
The power array has even length. In each operation, pick any two of its position values x and y, gain the sum of the closed interval arr[min(x,y)..max(x,y)], and then remove these two elements from power. Maximize the total gain after all operations, modulo 10^9+7.
输入格式
The input contains N and K, then N non-negative arr values, then K positions. This site adds 1≤N≤200000, 2≤K≤2000 with K even, every position in [0,N−1], and arr[i]≤10^9.
输出格式
Output the maximum total gain modulo 10^9+7.
样例 1
输入:
5 4
3 5 6 0 7
3 1 0 2
输出:
25
样例 2
输入:
3 2
1 2 3
0 2
输出:
6
样例 3
输入:
2 2
0 0
1 0
输出:
0