#include using namespace std; const int SIZE = 555; int N, B; int X[SIZE], Y[SIZE], P[SIZE]; int mat_p[SIZE][SIZE], dp_p[SIZE][SIZE]; int mat_c[SIZE][SIZE], dp_c[SIZE][SIZE]; void compress(){ map xs, ys; for(int i=0;i= 0)res -= dp[y-1][x+w-1]; if(x - 1 >= 0)res -= dp[y+h-1][x-1]; if(y - 1 >= 0 && x - 1 >= 0){ res += dp[y-1][x-1]; } return res; } int solve(){ compress(); int H = 0, W = 0; for(int i=0;i 0 && calc_range(y, x, h, ws, dp_p) > B)--ws; if(ws == 0)break; res = max(res, calc_range(y, x, h, ws, dp_c)); } } return res; } int main(){ cin >> N >> B; for(int i=0;i> X[i] >> Y[i] >> P[i]; cout << solve() << endl; return 0; }