You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
928 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
#define int long long
#define endl "\n"
int a[N], s[N];
int n, k; // n个城市传送半径为k
2 years ago
int res;
2 years ago
signed main() {
cin >> n >> k; // n个城市传送半径为k
for (int i = 1; i < n; i++) { // 以起点为线段命名的编号,所以1~n共n个城市,其实是n-1条线段
cin >> a[i]; // 走这条路要耗费时间a[i]
s[i] += s[i - 1] + a[i]; // 前缀和
}
2 years ago
/*
1[1,n-1]k
2, [1,n-k]
3a[1],使s[1]-s[0],i0
*/
for (int i = 0; i + k < n; i++) res = max(res, s[i + k] - s[i]);
cout << s[n - 1] - res << endl;
2 years ago
}