mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 20:36:28 +00:00
21 lines
384 B
C++
21 lines
384 B
C++
|
#include <bits/stdc++.h>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
int n, k;
|
||
|
long long a, cnt, sum[1000005];
|
||
|
|
||
|
int main() {
|
||
|
cin >> n >> k;
|
||
|
for (int i = 1; i < n; i++) {
|
||
|
cin >> a;
|
||
|
sum[i] = sum[i - 1] + a;
|
||
|
}
|
||
|
cnt = sum[k];
|
||
|
for (int i = 2; i <= n - k; i++) {
|
||
|
cnt = max(cnt, sum[i + k - 1] - sum[i - 1]);
|
||
|
}
|
||
|
cout << sum[n - 1] - cnt << endl;
|
||
|
return 0;
|
||
|
}
|