#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 < N; i++){ cin >> X[i] >> Y[i] >> P[i]; } int ans = 0; for (int i = 0; i < N; i++){ for (int j = i; j < N; j++){ int D = min(Y[i], Y[j]); int U = max(Y[i], Y[j]); map p, c; for (int k = 0; k < N; k++){ if (D <= Y[k] && Y[k] <= U){ p[X[k]] += P[k]; c[X[k]]++; } } vector p2; for (auto x : p){ p2.push_back(x.second); } vector c2; for (auto x : c){ c2.push_back(x.second); } int cnt = p2.size(); vector sp(cnt + 1); sp[0] = 0; for (int k = 0; k < cnt; k++){ sp[k + 1] = sp[k] + p2[k]; } vector sc(cnt + 1); sc[0] = 0; for (int k = 0; k < cnt; k++){ sc[k + 1] = sc[k] + c2[k]; } for (int k = 0; k <= cnt; k++){ ans = max(ans, sc[upper_bound(sp.begin(), sp.end(), sp[k] + B) - sp.begin() - 1] - sc[k]); } } } cout << ans << endl; }