#include #include #include #include #include #include #include #include #include #include using namespace std; int main(){ int N,B; cin >> N >> B; vector X(N), Y(N), P(N); for(int i=0; i> X[i] >> Y[i] >> P[i]; auto compress = [&](vector& V){ auto V__ = V; sort(V__.begin(), V__.end()); V__.erase( unique(V__.begin(), V__.end()), V__.end()); for(int i=0; i> sum_p(width, vector(height, 0)); vector> sum_c(width, vector(height, 0)); for(int i=0; i0){ sum_p[i][j] += sum_p[i][j-1]; sum_c[i][j] += sum_c[i][j-1]; } if(i>0){ sum_p[i][j] += sum_p[i-1][j]; sum_c[i][j] += sum_c[i-1][j]; } if(i>0 && j>0){ sum_p[i][j] -= sum_p[i-1][j-1]; sum_c[i][j] -= sum_c[i-1][j-1]; } } } //[ (a,b) , (c,d) ] auto get_points = [&](int a, int b, int c, int d){ int ret = 0; ret += sum_p[c][d]; if(a>0) ret -= sum_p[a-1][d]; if(b>0) ret -= sum_p[c][b-1]; if(a>0 && b>0) ret += sum_p[a-1][b-1]; return ret; }; //[ (a,b) , (c,d) ] auto get_counts = [&](int a, int b, int c, int d){ int ret = 0; ret += sum_c[c][d]; if(a>0) ret -= sum_c[a-1][d]; if(b>0) ret -= sum_c[c][b-1]; if(a>0 && b>0) ret += sum_c[a-1][b-1]; return ret; }; int ans = 0; for(int i=0; i= 0) ub = last+1; while(ub-lb>1){ int med = (lb+ub)/2; int val = get_points(i,j, k,med); if(val > B){ ub = med; }else{ lb = med; } } if(get_points(i,j, k,lb) <= B) ans = max(ans, get_counts(i,j, k,lb)); last = lb; } } } cout << ans << endl; return 0; }