#include #include using namespace std; using i64 = long long; int n; void fast_zeta(vector& v) { for (int j = 0; j < n; j++) { for (int i = 0; i < (1 << n); i++) { if (i >> j & 1) { v[i] = max(v[i], v[i ^ (1 << j)]); } } } } void slow_zeta(vector& v) { for (int i = 0; i < (1 << n); i++) { for (int j = i; j >= 0; j--) { j &= i; v[i] = max(v[i], v[j]); } } } int main() { i64 m, q; cin >> n >> m >> q; vector a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; vector dpm(1 << n), dpq(1 << n); for (int i = 0; i < (1 << n); i++) { i64 p = 0, v = 0; for (int j = 0; j < n; j++) { if (i >> j & 1) { p += a[j]; v += b[j]; } } if (p <= m) dpm[i] = v; if (p <= q) dpq[i] = v; } fast_zeta(dpm); fast_zeta(dpq); // slow_zeta(dpm); // slow_zeta(dpq); int mask = (1 << n) - 1; i64 ans = 0; for (int i = 0; i < (1 << n); i++) { int sub = mask ^ i; ans = max(ans, dpm[i] + dpq[sub]); } cout << ans << endl; }