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.

26 lines
485 B

#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
typedef long long ll;
int a[N];
ll s[N], f[N];
/*
BruteForce
通过了 9/12个数据
*/
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> s[i], s[i] += s[i - 1];
// 暴力大法
for (int i = 1; i <= n; i++)
for (int j = i; j >= i - m; j--)
f[i] = max(f[i], f[j - 1] + s[i] - s[j]);
cout << f[n] << endl;
return 0;
}