Isn't this just an n-square dp... Looking at the Luogu problem solution, it's a fairy fight
. I didn't use n in the whole process...
Incorporate the rest time into the milk production time, and pay attention to "no milking at the end time", so ei=ei+ r-1, watch out for this -1!
Then sort by r, let f[i] be the maximum benefit of selecting i, because r is monotonic, so swipe directly from left to right to satisfy rj<li, and take a max (in fact, it can be divided into two, but the data is very watery Just write the violent enumeration)
and then take the max of ans and all f.
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const long long N=1005;
int n,m,k,f[N],ans;
struct qwe
{
int l,r,v;
}a[N];
bool cmp(const qwe &a,const qwe &b)
{
return a.r<b.r;
}
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
int main()
{
n=read(),m=read(),k=read();
for(int i=1;i<=m;i++)
a[i].l=read(),a[i].r=read()+k-1,a[i].v=read();
sort(a+1,a+1+m,cmp);
for(int i=1;i<=m;i++)
{
for(int j=0;j<i&&a[j].r<a[i].l;j++)
f[i]=max(f[i],f[j]);
f[i]+=a[i].v;
ans=max(ans,f[i]);
}
printf("%d\n",ans);
return 0;
}