Rt,比答案小
//f(i,j):前i棵树中种了j棵的最大值.
//f(i,j)=max(f(i-1,j),f(i-2,j-1)+a(i)).
#include<bits/stdc++.h>
using namespace std;
const int mxN(6e3),INF(0x3f3f3f3f);
int n,k;
int a[mxN+5],f[mxN+5][mxN+5],ans;
int main(){
// freopen("in.txt","r",stdin);
scanf("%d%d",&n,&k);
for(int i(1);i<=n;++i)scanf("%d",&a[i]);
memset(f,-0x3f,sizeof(f));
f[1][0]=0,f[1][1]=a[1],ans=max(0,a[1]);
for(int i(2);i<=n;++i)
for(int j(0);j<=k;++j)
f[i][j]=max(f[i-1][j],(j-1>=1)?(f[i-2][j-1]+a[i]):(-INF)),ans=max(ans,f[i][j]);
printf("%d",ans);
return 0;
}