#include #define REP(i, n) for (int i = 0; (i) < int(n); ++ (i)) #define ALL(x) begin(x), end(x) using ll = long long; using namespace std; template inline void chmax(T & a, T const & b) { a = max(a, b); } ll knapsack_problem_branch_and_bound(int n, ll max_w, const vector & a_v, const vector & a_w) { vector v(n), w(n); { vector xs(n); iota(ALL(xs), 0); sort(ALL(xs), [&](int i, int j) { return 1.0 * a_v[i] * a_w[j] > 1.0 * a_v[j] * a_w[i]; }); REP (i, n) { v[i] = a_v[xs[i]]; w[i] = a_w[xs[i]]; } } ll ans = 0; function go = [&](int i, ll cur_v, ll cur_w) { if (max_w < cur_w) return; // not executable if (i == n) { chmax(ans, cur_v); return; // terminate } ll lr_v = cur_v; // linear relaxation ll lr_w = cur_w; int j = i; for (; j < n and lr_w + w[j] <= max_w; ++ j) { // greedy lr_w += w[j]; lr_v += v[j]; } if (lr_w == max_w or j == n) { chmax(ans, lr_v); return; // accept greedy } if (lr_v + 1.0 * v[j] * (max_w - lr_w) / w[j]<= ans) return; // bound go(i + 1, cur_v + v[i], cur_w + w[i]); go(i + 1, cur_v, cur_w ); }; go(0, 0, 0); return ans; } int main() { int n; ll max_w; cin >> n >> max_w; vector v(n), w(n); REP (i, n) cin >> v[i] >> w[i]; ll result = knapsack_problem_branch_and_bound(n, max_w, v, w); cout << result << endl; return 0; }