#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 < N; i++){ cin >> X[i] >> Y[i] >> P[i]; } int ans = 0; for (int i = 0; i < N; i++){ for (int j = i + 1; j < N; j++){ int D = min(Y[i], Y[j]); int U = max(Y[i], Y[j]); map p, c; set st; for (int k = 0; k < N; k++){ if (D <= Y[k] && Y[k] <= U){ p[X[k]] += P[k]; c[X[k]]++; st.insert(X[k]); } } vector p2, c2; for (int x : st){ p2.push_back(p[x]); c2.push_back(c[x]); } int cnt = st.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; }