#include using namespace std; using SS = pair; class SegmentTree{ public: int siz = -1,n = -1; vector dat; SS op(SS a, SS b){return {a.first+b.first,a.second+b.second};} SS e(){return {0,0};} void renew (SS &a,SS x){ a = op(a,x); //a = x; //set(pos,x)で可能. //その他. } SegmentTree(int N){init(N);} SegmentTree(const vector &A){//長さ配列サイズに合わせる. siz = 1; n = A.size(); while(siz < n) siz *= 2; dat.resize(siz*2,e()); for(int i=0; i0; i--) dat.at(i) = op(dat.at(i*2),dat.at(i*2+1)); } void init(int N){ //全要素単位元に初期化. siz = 1; n = N; while(siz < n) siz *= 2; dat.assign(siz*2,e()); } void init(const vector &A){//長さ配列サイズに合わせる. siz = 1; n = A.size(); while(siz < n) siz *= 2; dat.resize(siz*2,e()); for(int i=0; i0; i--) dat.at(i) = op(dat.at(i*2),dat.at(i*2+1)); } void set(int pos,SS x){ pos = pos+siz; dat.at(pos) = x; while(pos != 1){ pos = pos/2; dat.at(pos) = op(dat.at(pos*2),dat.at(pos*2+1)); } } void update(int pos,SS x){ pos = pos+siz; renew(dat.at(pos),x); while(pos != 1){ pos = pos/2; dat.at(pos) = op(dat.at(pos*2),dat.at(pos*2+1)); } } SS findans(int l, int r){ SS retl = e(),retr = e(); l += siz,r += siz; while(l < r){ if(l&1) retl = op(retl,dat.at(l++)); if(r&1) retr = op(dat.at(--r),retr); l >>= 1; r >>= 1; } return op(retl,retr); } SS get(int pos){return dat.at(pos+siz);} SS rangeans(int l, int r){return findans(l,r);} SS allrange(){return dat.at(1);} //rightは) leftは[で 渡す&返す. int maxright(const function f,int l = 0){ //fを満たさない最小の箇所を返す なければn. l += siz; int r = n+siz; vector ls,rs; while(l < r){ if(l&1) ls.push_back(l++); if(r&1) rs.push_back(--r); l >>= 1; r >>= 1; } SS okl = e(); for(int i=0; i=0; i--){ l = rs.at(i); SS now = op(okl,dat.at(l)); if(!f(now)){ while(l < siz){ l <<= 1; now = op(okl,dat.at(l)); if(f(now)){okl = now; l++;} } return l-siz; } okl = now; } return n; } int minleft(const function f,int r = -1){ //fを満たす最小の箇所を返す なければ0. if(r == -1) r = n; int l = siz; r += siz; vector ls,rs; while(l < r){ if(l&1) ls.push_back(l++); if(r&1) rs.push_back(--r); l >>= 1; r >>= 1; } SS okr = e(); for(int i=0; i=0; i--){ r = ls.at(i); SS now = op(dat.at(r),okr); if(!f(now)){ while(r < siz){ r <<= 1; r++; now = op(dat.at(r),okr); if(f(now)){okr = now; r--;} } return r+1-siz; } okr = now; } return 0; } }; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); long long N,B; cin >> N >> B; int n = 100000; vector V(n+1),V2(n+1); vector C(N),S(N); for(auto &c : C) cin >> c; for(auto &s : S) cin >> s; for(int i=0; i give(n+1); for(int i=1; i<=n; i++) give.at(i) = {V.at(i),V.at(i)*i}; SegmentTree Z(give); auto f = [&](SS x) -> bool {return x.second<=B;}; long long answer = 0; for(int i=1; i<=n; i++) if(V2.at(i)){ Z.update(i,{-V2.at(i),-V2.at(i)*i}); Z.update(1,{V2.at(i),V2.at(i)}); int r = Z.maxright(f); auto [now,cost] = Z.rangeans(0,r); if(r < n+1) now += (B-cost)/r; answer = max(answer,now); Z.update(1,{-V2.at(i),-V2.at(i)}); Z.update(i,{V2.at(i),V2.at(i)*i}); } cout << answer << "\n"; }