/* * ===================================================================================== * * Filename: a.cc * Version: 1.0 * Created: 03/14/2015 07:57:23 PM * Revision: none * Compiler: GNU C++ * * I don't want to be alone. * * ===================================================================================== */ #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define PB push_back #define SIZE(x) (int)x.size() #define clr(x,y) memset(x,y,sizeof(x)) #define MP(x,y) make_pair(x,y) #define RS(n) scanf ("%s", n) #define ALL(t) (t).begin(),(t).end() #define FOR(i,n,m) for (int i = n; i <= m; i ++) #define ROF(i,n,m) for (int i = n; i >= m; i --) #define IT iterator #define FF first #define SS second typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef vector vint; typedef vector vstring; typedef pair PII; void RI (int& x){ x = 0; char c = getchar (); while (!(c>='0' && c<='9' || c=='-')) c = getchar (); bool flag = 1; if (c == '-'){ flag = 0; c = getchar (); } while (c >= '0' && c <= '9'){ x = x * 10 + c - '0'; c = getchar (); } if (!flag) x = -x; } void RII (int& x, int& y){RI (x), RI (y);} void RIII (int& x, int& y, int& z){RI (x), RI (y), RI (z);} void RC (char& c){ c = getchar (); while (c == ' '||c == '\n') c = getchar (); } char RC (){ char c = getchar (); while (c == ' '||c == '\n') c = getchar (); return c; } /**************************************END define***************************************/ const ll mod = 1e9+7; const ll LINF = 1e18; const int INF = 1e9; const double EPS = 1e-8; ll a[4000000]; struct A{ int x, y, z; friend bool operator < (const A& a, const A& b){ if (a.z - a.x != b.z - b.x){ return a.z - a.x < b.z - b.x; } } }b[50]; int main (){ int n, w; while (~scanf ("%d%d", &n, &w)){ int top = 0; clr (a, 0); FOR (i, 1, n){ RIII (b[i].x, b[i].y, b[i].z); } sort (b+1, b+n+1); FOR (i, 1, n){ int t, v, l; t = b[i].x, v = b[i].y, l = b[i].z; int le = max (l-t, 0); int re = max (top + t, l); FOR (j, top+1, re){ a[j] = a[j-1]; } top = re; ROF (j, re-t, le){ a[j+t] = max (a[j+t], v + a[j]); } /*FOR (i, 0, top){ cout << a[i] << " "; } cout << endl;*/ } int ans = -1; FOR (i, 0, top){ if (a[i] >= w){ ans = i; break; } } if (ans != -1) printf ("%d\n", ans); else puts ("zhx is naive!"); } }