水题
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pii pair<int, int>
using namespace std;
const int maxn = 1e5+10;
const ll inf = 1e18;
template <typename _tp>
inline void read(_tp& x) {
char ch = getchar(), sgn = 0;
while (ch ^ '-' && !isdigit(ch)) ch = getchar();
if (ch == '-') ch = getchar(), sgn = 1;
for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
if (sgn) x = -x;
}
int f[maxn][110][2];
int n, m, a[maxn];
signed main(){
read(n), read(m);
for(int i = 1; i <= n; ++i) read(a[i]);
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= min(i, m); ++j){
f[i][j][1] = max(f[i-1][j][1] + a[i], f[i-1][j-1][0] + a[i]);
f[i][j][0] = max(f[i-1][j][0], f[i-1][j][1]);
}
}
printf("%lld", max(f[n][m][1], f[n][m][0]));
//return 0;
}

京公网安备 11010502036488号