0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

#15. 牢不可破的子序列

https://sjzezoj.com/submission/21445
This commit is contained in:
Baoshuo Ren 2021-08-23 20:24:57 +08:00 committed by Baoshuo Ren
parent 311bc9f385
commit 45c209072e
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

24
S2OJ/15/15.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <bits/stdc++.h>
using namespace std;
int n, k, a;
long long sum[5000005], f[5000005], now = INT_MIN;
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a;
sum[i] = sum[i - 1] + a;
}
for (int i = 1; i <= n; ++i) {
f[i] = f[i - 1];
if (i - k >= 0) {
now = max(now, f[i - k] - sum[i - k]);
f[i] = max(f[i], now + sum[i]);
}
}
cout << f[n] << endl;
return 0;
}