#include #include using namespace std; using namespace atcoder; #define ll long long #define rep(i,a,b) for(int i=(a);i<(b);i++) #define repl(i,a,b) for(ll i=(a);i<(b);i++) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() template bool chmin(T &a,T b){if(a>b){a=b;return true;} return false;} template bool chmax(T &a,T b){if(a> n; ll b; cin >> b; segtree sg(n),cnt(n); vector> p(n); rep(i,0,n) cin >> p[i].first; rep(i,0,n) cin >> p[i].second; sort(all(p)); rep(i,0,n) sg.set(i,p[i].first*p[i].second); rep(i,0,n) cnt.set(i,p[i].second); ll ans=0; rep(i,0,n){ if(p[i].second>=b){ chmax(ans,b); } else{ ll tmp=p[i].second; target=b-p[i].second; sg.set(i,0); cnt.set(i,0); int r=sg.max_right(0); if(r == n){ tmp+=cnt.prod(0,r); chmax(ans,tmp); } else{ tmp+=cnt.prod(0,r); tmp+=(target-sg.prod(0,r))/p[r].first; chmax(ans,tmp); } sg.set(i,p[i].first*p[i].second); cnt.set(i,p[i].second); } } cout << ans << "\n"; return; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T=1; // cin >> T; while(T--) solve(); }