AmazonOA #296
Minimum Cost to Convert Products to Variant A
估计困难可在线判题
products is a 0/1 array. Each time, you must choose exactly k consecutive positions, pay the current number of 1s in that window, and then change one 1 in the window to 0. Find the minimum total cost to clear all 1s; if everything is already 0, no operation is needed.
输入格式
The first line contains n k and the second line contains products. The original statement specifies binary values and 1≤k≤n, with no upper bound on n; this site adds 1≤n≤200000.
输出格式
Output a single integer, the answer.
样例 1
输入:
3 3
1 1 1
输出:
6
样例 2
输入:
5 2
1 0 1 0 1
输出:
3
样例 3
输入:
2 1
0 0
输出:
0
样例说明
The answers are 6, 3 and 0. In the first example you must choose all three positions every time, paying 3, 2 and 1 in turn.