#include #include #include #include #include #include using namespace std; int N; int B; struct Point { Point() {} Point(int x, int y, int p) : x(x), y(y), p(p) {} int x; int y; int p; }; vector points; void input(istream& in) { in >> N >> B; points.resize(N); for (int i = 0; i < N; i++) { in >> points[i].x >> points[i].y >> points[i].p; } } int resolve() { map> Xmap; map> Ymap; for (int i = 0; i < N; i++) { Xmap[points[i].x].push_back(&points[i]); Ymap[points[i].y].push_back(&points[i]); } vector X; for (auto ite : Xmap) { X.push_back(ite.first); } vector Y; for (auto ite : Ymap) { Y.push_back(ite.first); } int best_count = 0; for (size_t ix1 = 0; ix1 < X.size(); ix1++) { int x1 = X[ix1]; for (size_t ix2 = ix1; ix2 < X.size(); ix2++) { int x2 = X[ix2]; for (size_t iy1 = 0; iy1 < Y.size(); iy1++) { int y1 = Y[iy1]; int count = 0; int score = 0; for (size_t iy2 = iy1; iy2 < Y.size(); iy2++) { int y2 = Y[iy2]; for (auto ppoint : Ymap[y2]) { if (x1 <= ppoint->x && ppoint->x <= x2) { count++; score += ppoint->p; } } if (score > B) { break; } if (count > best_count) { best_count = count; } } } } } return best_count; } int main(int argc, char **argv) { input(cin); cout << resolve() << endl; return 0; }