cswork / OA打开练习工作台

MicrosoftOA #39

Maximize Sum of Two Non-Overlapping Fragments

估计困难可在线判题

考点(AI 标注)前缀和区间双指针滑窗

Choose two contiguous segments of lengths K and L; they may overlap. An element in only one segment counts at its original value, while an element in the overlap counts only once with its sign flipped. The title's "non-overlapping" conflicts with the statement, so this site follows the overlap sign-flip rule given by the statement and both examples.

输入格式

This site's ranges: the first line contains N K L (1≤N≤2000, 1≤K,L≤N), and the second line contains N integers (−10⁹..10⁹).

输出格式

Output a single integer, the answer.

样例 1

输入:

5 3 2
1 3 -4 2 -1

输出:

10

样例 2

输入:

3 1 3
-5 -3 -4

输出:

-2

样例 3

输入:

2 1 1
1 2

输出:

3

样例说明

Example 1: choose indices 0..2 and 2..3; −4 becomes 4, for a total of 1+3+4+2=10.

Example 2: the whole array overlaps the single element −5, turning −5 into 5, for a total of 5−3−4=−2.

Example 3: choose 1 and 2 separately with no overlap, for a total of 3.