#include typedef long long ll; typedef unsigned long long ull; #define FOR(i,a,b) for(int (i)=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define RANGE(vec) (vec).begin(),(vec).end() using namespace std; pair operator+(const pair &a, const pair &b) { return make_pair(a.first+b.first, a.second+b.second); } pair operator-(const pair &a, const pair &b) { return make_pair(a.first-b.first, a.second-b.second); } class SurroundWithSquare { public: void dump(const pair &a) { cerr<>N>>B; // 座標圧縮を使う vector xs; vector ys; vector> ps; REP(i,N) { ll x,y,p; cin>>x>>y>>p; ps.emplace_back(x,y,p); xs.push_back(x); ys.push_back(y); } sort(RANGE(xs)); sort(RANGE(ys)); map xmap; map ymap; REP(i,N) { xmap.emplace(xs[i],xmap.size()); ymap.emplace(ys[i],ymap.size()); } const int maxX = xmap.size(); const int maxY = ymap.size(); // 0<=x,y<400 pair field[maxY][maxX]; REP(y,maxY) REP(x,maxX) field[y][x] = make_pair(0,0); REP(i,N) { ll x,y,p; tie(x,y,p) = ps[i]; field[ymap[y]][xmap[x]] = make_pair(p,1); } pair Sum[maxY+1][maxX+1]; // 累積和を計算する(レンジは半開区間) REP(y,maxY) REP(x,maxX) Sum[y+1][x+1] = field[y][x]; REP(y,maxY+1) REP(x,maxX) { Sum[y][x+1] = Sum[y][x+1] + Sum[y][x]; } REP(y,maxY) REP(x,maxX+1) { Sum[y+1][x] = Sum[y+1][x] + Sum[y][x]; } ll maxN = 0; // 半全探索・しゃくとり法 REP(uy,maxY+1) REP(ly,uy+1) { for (int lx = 0, ux = lx; ; ++lx) { for (; ux <= maxX; ++ux) { auto cnt = Sum[uy][ux] - Sum[uy][lx] - Sum[ly][ux] + Sum[ly][lx]; if (cnt.first > B) break; maxN = max(maxN, cnt.second); } if (ux >= maxX) break; } } cout<solve(); delete obj; return 0; } #endif