#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define BET(a,b,c) ((a)<=(b)&&(b)<(c)) #define FOR(i,n) for(int i=0,i##_end=(int(n));i VI; typedef vector VVI; struct point{ int x,y,p; }; int main() { int N,B; cin>>N>>B; vector points(N); VI xx ; FOR(i,N){ cin>>points[i].x>>points[i].y>>points[i].p; xx.push_back(points[i].x); } sort(ALL(points), [](const point&p1,const point&p2){ return p1.y < p2.y; }); sort(ALL(xx)); xx.erase(unique(xx.begin(),xx.end()),xx.end()); int ans = 0 ; FOR(j,SZ(xx)) FOR(i,j+1) { int x1 = xx[i]; int x2 = xx[j]; map histCount, histPoint; FOR(k,N){ if(x1 <= points[k].x && points[k].x <= x2) { histCount[points[k].y] ++; histPoint[points[k].y] += points[k].p; } } int cnt = 0; int total = 0 ; deque deqTotal, deqCount; for(const auto p : histPoint){ int y = p.first; int pp = p.second; int cc = histCount[y]; total += pp; cnt += cc; deqTotal.push_back(pp); deqCount.push_back(cc); while(total > B){ total -= deqTotal[0]; cnt -= deqCount[0]; deqCount.pop_front(); deqTotal.pop_front(); } if(total <= B){ ans = max(ans, cnt); } } } cout<