#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; int N; ll H; ll A[200009], B[200009], S[200009]; int main() { cin >> N >> H; for(int i = 1; i <= N; ++i) cin >> A[i]; for(int i = 1; i <= N; ++i) cin >> B[i]; for(int i = 1; i <= N; ++i) S[i] = S[i-1]+B[i]; int r = 1; ll ans = 0, sum = 0, hi = 0; for(int l = 1; l <= N; ++l) { r = max(r,l); while(r <= N && hi+B[r]*(r-l+1) <= H) { sum += A[r]; hi += B[r]*(r-l+1); r++; } // cout << "l,r,sum:" << l << "," << r << endl; // cout << "sum,hi:" << sum << "," << hi << endl; ans = max(ans,sum); if(r > l) { hi -= S[r-1]-S[l-1]; sum -= A[l]; } } cout << ans << endl; }