#include using namespace std; typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for(int i = (l) ; i < (r); i++) #define incII(i, l, r) for(int i = (l) ; i <= (r); i++) #define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--) #define decII(i, l, r) for(int i = (r) ; i >= (l); i--) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define UB upper_bound #define LB lower_bound #define PQ priority_queue #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define FOR(it, v) for(auto it = v.begin(); it != v.end(); ++it) #define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it) template bool setmin(T & a, T b) { if(b < a) { a = b; return true; } else { return false; } } template bool setmax(T & a, T b) { if(b > a) { a = b; return true; } else { return false; } } template bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } } template bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } } template T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template T lcm(T a, T b) { return a / gcd(a, b) * b; } // ---- ---- int n, b, x[400], y[400], p[400]; vector vx, vy; map mx, my; int sn[401][401], sp[401][401]; int main() { cin >> n >> b; inc(i, n) { cin >> x[i] >> y[i] >> p[i]; } inc(i, n) { vx.PB(x[i]); } inc(i, n) { vy.PB(y[i]); } sort(ALL(vx)); int xs = unique(ALL(vx)) - vx.begin(); sort(ALL(vy)); int ys = unique(ALL(vy)) - vy.begin(); inc(i, xs) { mx[vx[i]] = i; } inc(i, ys) { my[vy[i]] = i; } inc(i, n) { sn[mx[x[i]] + 1][my[y[i]] + 1] = 1; sp[mx[x[i]] + 1][my[y[i]] + 1] = p[i]; } inc1(i, xs) { inc1(j, ys) { sn[i][j] += sn[i - 1][j]; sp[i][j] += sp[i - 1][j]; } } inc1(i, xs) { inc1(j, ys) { sn[i][j] += sn[i][j - 1]; sp[i][j] += sp[i][j - 1]; } } int ans = 0; inc(i1, xs) { inc(j1, ys) { incII(i2, i1 + 1, xs) { incII(j2, j1 + 1, ys) { int rn = sn[i2][j2] - sn[i1][j2] - sn[i2][j1] + sn[i1][j1]; int rp = sp[i2][j2] - sp[i1][j2] - sp[i2][j1] + sp[i1][j1]; if(rp <= b) { setmax(ans, rn); } else { break; } } } } } cout << ans << endl; return 0; }