P5638 【CSGRound2】光骓者的荣耀
点击查看代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1000005;
int n, k;
ll s[N], mx;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
for (int i = 1; i < n; i++) {
ll x; cin >> x;
s[i] = s[i-1] + x;
}
if (k >= n - 1) {
cout << 0 << endl;
return 0;
}
for (int i = 0; i + k < n; i++) {
mx = max(mx, s[i+k] - s[i]);
}
cout << s[n-1] - mx << endl;
return 0;
}

浙公网安备 33010602011771号