_Lightning_ @ 2024-04-04 20:54:30
```cpp
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=100010;
int n,k,a[maxn],sum[maxn],dp[maxn];
signed main(){
scanf("%lld%lld",&n,&k);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
sum[i]=sum[i-1]+a[i];
}
for(int i=1;i<=n+1;i++){
for(int j=max(1ll*0,i-k-1);j<i;j++){
dp[i]=max(dp[i],dp[j]+sum[i-1]-sum[j]);
}
}
printf("%lld\n",dp[n+1]);
return 0;
}
```