#include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector VI; typedef vector VVI; #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) #define FOR(i, f, t) for(int(i)=(f);(i)<(t);(++i)) #define RREP(i, n) for(int(i)=(n)-1;(i)>=0;--(i)) #define FOREACH(it, c) for(auto it=(c).begin();it!=(c).end();++it) const int MOD = int(1e9+7); int res = 0; int N, B; int x[444],y[444],p[444]; int m1[444][444]; int m2[444][444]; int s1(int x1, int y1, int x2, int y2){ int sum = m1[y2][x2]; if(x1 > 0) sum -= m1[y2][x1-1]; if(y1 > 0) sum -= m1[y1-1][x2]; if(x1 > 0 && y1 > 0) sum += m1[y1-1][x1-1]; return sum; } int s2(int x1, int y1, int x2, int y2){ int sum = m2[y2][x2]; if(x1 > 0) sum -= m2[y2][x1-1]; if(y1 > 0) sum -= m2[y1-1][x2]; if(x1 > 0 && y1 > 0) sum += m2[y1-1][x1-1]; return sum; } int main(){ do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0); cin >> N >> B; map mx, my; REP(i,N){ cin >> x[i] >> y[i] >> p[i]; mx[x[i]] = 1; my[y[i]] = 1; } int w = 0; FOREACH(it, mx) it->second = w++; int h = 0; FOREACH(it, my) it->second = h++; REP(i,N){ int xx = mx[x[i]], yy = my[y[i]]; m1[yy][xx] += p[i]; m2[yy][xx] ++; } FOR(x,1,w){ m1[0][x] = m1[0][x] + m1[0][x-1]; m2[0][x] = m2[0][x] + m2[0][x-1]; } FOR(y,1,h){ m1[y][0] = m1[y][0] + m1[y-1][0]; m2[y][0] = m2[y][0] + m2[y-1][0]; } FOR(y,1,h) FOR(x,1,w){ m1[y][x] = m1[y][x] + m1[y][x-1] + m1[y-1][x] - m1[y-1][x-1]; m2[y][x] = m2[y][x] + m2[y][x-1] + m2[y-1][x] - m2[y-1][x-1]; } int maxv = 0; REP(y1,h)REP(x1,w){ int x2 = x1; for(int y2 = h-1; y2 >= y1; y2--){ while(x2 < w){ if(s1(x1,y1,x2,y2) > B) break; maxv = max(maxv, s2(x1,y1,x2,y2)); x2++; } } } cout << maxv << endl; return 0; }