区间按左端点排序,dp。
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 1001
struct Point{int l,r,w;}a[N];
bool operator < (const Point &a,const Point &b){return a.l<b.l;}
int n,m,K,f[N];
int main()
{
scanf("%d%d%d",&n,&m,&K);
for(int i=1;i<=m;++i) scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].w);
sort(a+1,a+m+1);
for(int i=1;i<=m;++i) f[i]=a[i].w;
for(int i=1;i<=m;++i)
for(int j=1;j<i;++j)
if(a[j].r+K<=a[i].l)
f[i]=max(f[i],f[j]+a[i].w);
printf("%d\n",*max_element(f+1,f+1+m));
return 0;
}