#include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define chmax(a,x) a = max(a, x) typedef long long ll; ll N, B; typedef pair pii; typedef pair pi3; vector p; int main() { set xset; cin >> N >> B; rep(i, N) { ll x, y, sc; cin >> x >> y >> sc; xset.insert(x); p.emplace_back(pii{x, y}, sc); } vector xs; for(auto e: xset) { xs.push_back(e); } sort(p.begin(), p.end()); ll ans = 0; rep(I, xs.size()) REP(J, I, xs.size()) { int i = lower_bound(p.begin(), p.end(), pi3{pii{xs[I], -1e9-1},0})-p.begin(); int j = lower_bound(p.begin(), p.end(), pi3{pii{xs[J], 1e9+1},0})-p.begin()-1; int L = i, R = i; ll sum = 0; while(L <= j && R <= j) { if(sum + p[R].second <= B) { sum += p[R++].second; chmax(ans, (ll)(R-L)); } else { sum -= p[L++].second; if(sum < 0) { R = L; sum = 0; } } } } cout << ans << endl; return 0; }