#include #include #include #include #include #include #include #include #include #include using namespace std; #define int long long int MOD = 1000000007; struct T { int v; int w; bool operator<(const T& right) const { return v * right.w > right.v * w; } }; struct State { int v; int w; //vector goods; bool operator<(const State& right) const { return v * right.w < right.v * w; } }; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N, W; cin >> N >> W; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i].v >> A[i].w; } sort(A.begin(), A.end()); int w = 0; int v = 0; priority_queue pq; priority_queue npq; State st; st.v = 0; st.w = 0; pq.push(st); int res = -1; for (int i = 0; i < N; i++) { while ((int)npq.size() > 0)npq.pop(); for (int j = 0; j < 1000; j++) { if (pq.size() == 0) break; st = pq.top(); pq.pop(); npq.push(st); st.v += A[i].v; st.w += A[i].w; if (st.w <= W) { res = max(res, st.v); npq.push(st); } } swap(pq, npq); } cout << res << endl; }