0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-05 15:18:47 +00:00
OI-codes/Luogu/P5638/P5638.cpp

21 lines
384 B
C++
Raw Normal View History

#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;
}