Input
There are several test cases in the input.
Each test case begin with two integers N, M (1 ≤ N ≤ 500, 1 ≤ M ≤ 5000), indicating the items’ number and the initial money.
Then N lines follow, each line contains three numbers Pi, Qi and Vi (1 ≤ Pi ≤ Qi ≤ 100, 1 ≤ Vi ≤ 1000), their meaning is in the description.
The input terminates by end of file marker.
Output
For each test case, output one integer, indicating maximum value iSea could get.
Sample Input
2 10
10 15 10
5 10 5
3 10
5 10 5
3 5 6
2 7 3
Sample Output
5
11
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int dp[N];
int v[N],w[N],c[N];
int n,m;
struct node
{
int v,w,c;
}a[N];
bool cmp(const node &a,const node &b)
{
return (a.w-a.v)<(b.w-b.v);
}
int main()
{
while(~scanf("%d %d",&n,&m))
{
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++) cin>>a[i].v>>a[i].w>>a[i].c;
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
for(int j=m;j>=a[i].w;j--)
dp[j]=max(dp[j],dp[j-a[i].v]+a[i].c);
cout<<dp[m]<<endl;
}
}