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.

18 lines
679 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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
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]; // 前缀和
}
int ans = s[n - 1]; // sum总和
// 这是在枚举什么?
for (int i = k; i < n; i++) ans = min(ans, s[n - 1] - (s[i] - s[i - k]));
cout << ans << endl;
}