#include using namespace std; using ll = long long; int main() { int N, B, X[500], Y[500], P[500]; cin >> N >> B; for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i] >> P[i]; } vector V; map>> M; for (int i = 0; i < N; i++) { V.emplace_back(X[i]); M[Y[i]].push_back({X[i], P[i]}); } M[-1000000001] = {}; sort(V.begin(), V.end()); int ans = 0; for (int i = 0; i < V.size(); i++) { for (int j = i; j < V.size(); j++) { auto y1 = M.begin(); auto y2 = M.begin(); int p = 0; int cnt = 0; while (y2 != M.end()) { if (p < B || y1 == y2) { y2++; if (y2 == M.end()) break; for (auto& t : (*y2).second) { if (V[i] <= t.first && t.first <= V[j]) { cnt++; p += t.second; } } if (p <= B) ans = max(ans, cnt); } else { for (auto& t : (*y1).second) { if (V[i] <= t.first && t.first <= V[j]) { cnt--; p -= t.second; } } y1++; if (p <= B) ans = max(ans, cnt); } } } } cout << ans << endl; }