#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 const INF = 1<<29; int N; ll B; map MX, MY; int X[555], Y[555], P[555]; vector> D[555]; 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; } MX[-INF] = MY[-INF] = 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(i, MX.size()) REP(j, i+1, MX.size()) { int num = 0; ll tot = 0; int lower = 0; rep(upper, MY.size()) { // 上に進む for(auto& e: D[upper]) { if(i <= e.first && e.first <= j) { num ++, tot += e.second; } } // 下を切り落とす while(tot > B) { for(auto& e: D[lower]) { if(i <= e.first && e.first <= j) { num --; tot -= e.second; } } lower++; } ma = max(ma, num); } } cout << ma << endl; return 0; }