#define _CRT_SECURE_NO_WARNINGS //#define _GLIBCXX_DEBUG #include using namespace std; typedef long long ll; typedef vector vi; typedef vector vvi; typedef pair pii; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(ll i=a; i istream & operator>>(istream & is, vector &); template ostream & operator<<(ostream & os, vector const &); template typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple const &){} template typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple const & t){ os << (n==0?"":" ") << get(t); _ot(os, t); } template ostream & operator<<(ostream & os, tuple const & t){ _ot<0>(os, t); return os; } template typename enable_if<(n>=sizeof...(T))>::type _it(istream &, tuple &){} template typename enable_if<(n< sizeof...(T))>::type _it(istream & is, tuple & t){ is >> get(t); _it(is, t); } template istream & operator>>(istream & is, tuple & t){ _it<0>(is, t); return is; } template istream & operator<<(istream & is, pair & p){ return is >> p.first >> p.second; } template ostream & operator<<(ostream & os, pair const & p){ return os << "(" << p.first << ", " << p.second << ") "; } template istream & operator>>(istream & is, vector & v){ rep(i,v.size()) is >> v[i]; return is; } template ostream & operator<<(ostream & os, vector const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; } #ifdef DEBUG #define dump(...) (cerr<<#__VA_ARGS__<<" = "< P; namespace std { bool operator<(P const & a, P const & b){ return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag(); } } int main(){ int N,B; while(cin >> N >> B){ vector> ps(N); rep(i,N){ int x,y,p; cin >> x >> y >> p; ps[i] = mp(P(x,y),p); } sort(all(ps)); ll ans = 0; rep(i,N){ for(int j=i+1;j<=N;j++){ vector> ys; loop(k,i,j){ ys.eb(ps[k].first.imag(),ps[k].second); } sort(all(ys), [](const pair & a, const pair & b){ int y1 = a.first.imag(), y2 = b.first.imag(); return y1 < y2; }); ll cur = 0; int ir = 0; rep(il,ys.size()){ while(ir < (int)ys.size() && cur+ys[ir].second <= B){ cur += ys[ir].second; ir++; } while(ir+1 < (int)ys.size() && ys[ir].second == ys[ir+1].second){ cur += ys[ir].second; ir++; } if(cur <= B) ans = max(ans,ir-il); cur-= ys[il].second; } } } cout << ans << endl; } }