/****************************************** * AUTHOR: BHUVNESH JAIN * * INSTITUITION: BITS PILANI, PILANI * ******************************************/ #include using namespace std; typedef long long LL; typedef long double LD; typedef pair pii; typedef pair pll; const int MAX = 2e5 + 5; int n, x, y; LL a[MAX], b[MAX], c[MAX], p[MAX]; LL dp[MAX]; LL absl(LL a, LL b) { if (a >= b) return a - b; return b - a; } LL solve(int idx) { if (idx == n+1) { return 0; } LL &res = dp[idx]; if (res == -1) { res = 0; for(int i = idx+1; i <= n; ++i) { if (c[i] > c[idx] && absl(a[i], a[idx]) <= x && absl(b[i], b[idx]) <= y) { res = max(res, p[i] + solve(idx+1)); } } } // printf("%d : %lld\n", idx, res); return res; } int main() { #ifndef ONLINE_JUDGE //freopen("inp.txt", "r", stdin); #endif scanf("%d %d %d", &n, &x, &y); for(int i = 1; i <= n; ++i) { scanf("%lld %lld %lld %lld", &a[i], &b[i], &c[i], &p[i]); } fill(dp, dp + MAX, -1); LL ans = 0; for(int i = n; i >= 1; --i) { ans = max(ans, p[i] + solve(i)); } printf("%lld\n", ans); return 0; }