https://www.luogu.org/problemnew/show/P1353
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int n,m,f[10005][505],a[10005];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
f[1][1]=a[1];
for(int i=2;i<=n;i++){f[i][0]=f[i-1][0];
for(int j=1;j<=min(i,m);j++){
f[i][0]=max(f[i-j][j],f[i][0]);
f[i][j]=max(f[i-1][j-1]+a[i],f[i][j]);
}
}/*
for(int i=1;i<=n;i++){
for(int j=0;j<=min(i,m);j++)
printf("%d ",f[i][j]);
cout<<endl;
}*/
printf("%d\n",f[n][0]);
return 0;
}