#include #include #include #include using namespace std; #define inRange(x,a,b) (a <= x && x <= b) typedef pair pii; int main(){ int n, b; cin >> n >> b; vector> vp; for(int i = 0; i < n; i++){ int x, y, p; cin >> x >> y >> p; vp.push_back({{x,y},p}); } int ans = 0; for(int i = 0; i < n; i++){ for(int j = i+1; j < n; j++){ int low = vp[i].first.second, high = vp[j].first.second; if(low > high) swap(low, high); map ms, mv; for(int k = 0; k < n; k++){ if(inRange(vp[k].first.second, low, high)){ ms[vp[k].first.first] += (vp[k].second); mv[vp[k].first.first]++; } } vector vs, vv; for(auto p : ms) vs.push_back(p.second); for(auto p : mv) vv.push_back(p.second); int l = 0, r = 0, sum = 0, cnt = 0; while(l < vs.size()){ while(r < vs.size() && sum+vs[r] <= b){ sum += vs[r]; cnt += vv[r]; r++; } ans = max(ans, cnt); sum -= vs[l]; cnt -= vv[l]; l++; if(vs[r] > b) l = ++r; } } } cout << ans << endl; return 0; }