#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair P; typedef pair Pd; int n; ll W; ll v[5001], w[5001]; int ind[5001]; ll ans; Pd rsolve(int i, double ws, double vs){ bool ok=1; for(int k=i; k0 && x<(double)w[ind[k]]){ ok=0; } ws+=x; vs+=x/(double)w[ind[k]]*(double)v[ind[k]]; } return Pd(vs, ok); } ll solve(int i, ll ws, ll vs){ if(i==n){ ans=max(vs, ans); return vs; } Pd p=rsolve(i, (double)ws, (double)vs); if(p.second){ ans=max(ans, (ll)p.first); return (ll)p.first; } if(p.first<(double)ans) return 0; ll ret=0; if(ws+w[ind[i]]<=W) ret=max(ret, solve(i+1, ws+w[ind[i]], vs+v[ind[i]])); ret=max(ret, solve(i+1, ws, vs)); ans=max(ret, ans); return ret; } int main() { cin>>n>>W; for(int i=0; i>v[i]>>w[i]; } sort(ind, ind+n, [&](int i, int j){ return (double)v[i]/(double)w[i]>(double)v[j]/(double)w[j];}); solve(0, 0, 0); cout<