#include #include #include #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) typedef long long ll; int N; ll B; map MX, MY; int X[500], Y[500], P[500]; vector> D[500]; int ma = 0; int main() { cin >> N >> B; rep(i, N) cin >> X[i] >> Y[i] >> P[i], MX[X[i]] = MY[Y[i]] = 0; int INF = 1e9+1; MX[-INF] = MY[-INF] = 0; MX[INF] = MY[INF] = 0; int x1 = 0, y1 = 0; for(auto& e: MX) e.second = x1++; for(auto& e: MY) e.second = y1++; rep(i, N) D[MY[Y[i]]].emplace_back(MX[X[i]], P[i]); rep(x1, MX.size()) REP(x2, x1, MX.size()) { int num = 0; ll tot = 0; y1 = 0; rep(y2, MY.size()) { for(auto& e: D[y2]) { if(e.first >= x1 && e.first <= x2) { num ++, tot += e.second; } } while(tot > B) { for(auto& e: D[y1]) { if(e.first >= x1 && e.first <= x2) { num --; tot -= e.second; } } y1++; } ma = max(ma, num); } } cout << ma << endl; return 0; }