Let f[i][j] be the i-th minute fatigue j, transfer from three situations, remember to take a break to judge whether the rest from i to n can recover to fatigue 0
#include<iostream>
#include<cstdio>
using namespace std;
const int N=10005,M=505;
int n,m,a[N],f[N][M];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
for(int j=m;j>=0;j--)
{
if(i+j<=n)
f[i+j][0]=max(f[i+j][0],f[i-1][j+1]);
if(j==0)
f[i][j]=max(f[i][j],f[i-1][0]);
else
f[i][j]=max(f[i][j],f[i-1][j-1]+a[i]);
}
printf("%d\n",f[n][0]);
return 0;
}