AmazonOA #332
Reduce Memory Usage
简单可在线判题
A data center has N processes, and processes[i] is the memory used by process i. You must delete exactly m processes at consecutive positions from the list so that the total memory used by the remaining processes is as small as possible. Output this minimum total.
输入格式
The first line contains two integers N and m. The second line contains N integers processes[0..N-1], separated by whitespace. 2≤N≤3×10^6, 2≤m≤99999 and m≤N, 2≤processes[i]≤999999999.
输出格式
Output one integer: the minimum total remaining memory after deleting a contiguous segment of m processes. The answer may exceed the 32-bit integer range.
样例 1
输入:
5 2
10 4 8 13 20
输出:
22
样例 2
输入:
4 3
5 9 2 7
输出:
5
样例 3
输入:
2 2
3 3
输出:
0
样例说明
Example 1: delete 13 and 20, leaving 10+4+8=22. Example 2: delete a contiguous segment of length 3 from [5,9,2,7]; deleting 5,9,2 leaves 7 and deleting 9,2,7 leaves 5, so the answer is 5. Example 3: when N=m=2, everything must be deleted, leaving 0.