/** * @FileName a.cpp * @Author kanpurin * @Created 2020.05.24 19:45:53 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int n, b; cin >> n >> b; vector< tuple< int, int, int > > a(n); // y,x,p vector< int > x(n); for (int i = 0; i < n; i++) { int s, t, u; cin >> s >> t >> u; a[i] = make_tuple(t, s, u); x[i] = s; } sort(x.begin(), x.end()); sort(a.begin(), a.end()); // puts("///"); // for (int i = 0; i < n; i++) { // cout << get<1>(a[i]) << " " << get<0>(a[i]) << " " << get<2>(a[i]) << endl; // } int ans = 0; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { // x[i] <= X <= x[j] vector< tuple< int, int, int > > vv; // y値,数,スコア for (int k = 0; k < n; k++) { if (x[i] <= get< 1 >(a[k]) && get< 1 >(a[k]) <= x[j]) { if (vv.size() == 0) { vv.push_back(make_tuple(get< 0 >(a[k]), 1, get< 2 >(a[k]))); } else if (get< 0 >(vv[vv.size() - 1]) == get< 0 >(a[k])) { vv[vv.size() - 1] = make_tuple(get< 0 >(vv[vv.size() - 1]), get< 1 >(vv[vv.size() - 1]) + 1, get< 2 >(vv[vv.size() - 1]) + get< 2 >(a[k])); } else { vv.push_back(make_tuple(get< 0 >(a[k]), 1, get< 2 >(a[k]))); } } } int rit = 0; int sum = 0; int cnt = 0; for (int lef = 0; lef < vv.size(); lef++) { while (rit < vv.size()) { if (sum + get< 2 >(vv[rit]) <= b) { sum += get< 2 >(vv[rit]); cnt += get< 1 >(vv[rit]); rit++; } else { rit++; break; } } ans = max(ans, cnt); // cout << x[i] << "-" << x[j] << " " << lef << "->" << rit << " " << ans << endl; if (rit == lef) { rit++; cnt = 0; } else { sum -= get< 2 >(vv[lef]); cnt -= get< 1 >(vv[lef]); } } } } cout << ans << endl; return 0; }