贪心+01背包
#include <cstdio>
#include <algorithm>
#define N 500
#define FOR(i,n) for(int i=0;i<n;i++)
#define RFOR(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
struct Node{
int p, q, val;
bool operator <(const Node &P )const {
return q-p < P.q-P.p;
}
}a[N];
int main(){
for(int n,M,dp[N*10+1];scanf("%d%d",&n,&M)!=EOF; ) {
FOR(i,n) scanf("%d%d%d",&a[i].p,&a[i].q,&a[i].val);
FOR(i,M+1) dp[i]=0;
sort(a,a+n);
FOR(i,n) RFOR(j,M,a[i].p) if( j>=a[i].q )
dp[j]=dp[j]>dp[j-a[i].p]+a[i].val?dp[j]:dp[j-a[i].p]+a[i].val;
printf("%d\n",dp[M]);
}
return 0;
}