#ifndef MY_HEADER #define MY_HEADER #include #include using namespace std; using namespace atcoder; using lint = long long; using ulint = unsigned long long; using llint = __int128_t; struct edge; using graph = vector>; #define endl '\n' constexpr int INF = 1<<30; constexpr lint INF64 = 1LL<<61; constexpr lint mod107 = 1e9+7; using mint107 = modint1000000007; constexpr long mod = 998244353; using mint = modint998244353; lint ceilDiv(lint x, lint y){if(x >= 0){return (x+y-1)/y;}else{return x/y;}} lint floorDiv(lint x, lint y){if(x >= 0){return x/y;}else{return (x-y+1)/y;}} lint Sqrt(lint x) {assert(x >= 0); lint ans = sqrt(x); while(ans*ans > x)ans--; while((ans+1)*(ans+1)<=x)ans++; return ans;} double Dist(double x1, double y1, double x2, double y2){return sqrt(pow(x1-x2, 2) + pow(y1-y2,2));} lint DistSqr(lint x1, lint y1, lint x2, lint y2){return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2); } string toString(lint n){string ans = "";if(n == 0){ans += "0";}else{while(n > 0){int a = n%10;char b = '0' + a;string c = "";c += b;n /= 10;ans = c + ans;}}return ans;} string toString(lint n, lint k){string ans = toString(n);string tmp = "";while(ans.length() + tmp.length() < k){tmp += "0";}return tmp + ans;} vectorprime;void makePrime(lint n){prime.push_back(2);for(lint i=3;i<=n;i+=2){bool chk = true;for(lint j=0;j= 0; i--) #define vec vector #define pb push_back #define eb emplace_back #define se second #define fi first #define al(x) x.begin(),x.end() #define ral(x) x.rbegin(),x.rend() struct edge{ edge(lint v, lint c = 1) {to = v, cost = c;} lint to; lint cost; }; #endif int main(){ lint N, B;cin >> N >> B; vecC(N), S(N); rep(i, N) cin >> C[i]; rep(i, N) cin >> S[i]; vec>P(N); rep(i, N) P[i] = {C[i], S[i]}; sort(al(P)); lint bt = 0; lint maxx = 0; lint ans = 0; int t = 0; rep(i, N) { lint k = P[i].first * P[i].second; if(k+bt <= B) { ans += P[i].second; maxx = max(maxx, k - P[i].second); bt += k; t = i; } else break; } lint rans = ans; lint lans = ans; // 右側を1にする場合 { lint ms = 0; repp(i, t+1, N) { ms = max(ms, P[i].second); } rans += min(ms, B - bt); } // 左側を1にする場合 { bt -= maxx; repp(i,t+1, N) { lint k = P[i].first * P[i].second; if(k+bt <= B) { lans += P[i].second; bt += k; t = i; } else { lans += (B - bt) / P[i].first; break; } } } ans = max(lans, rans); cout << ans << endl; }