// #pragma GCC optimize("O3,unroll-loops") #include // #include using namespace std; #if __cplusplus >= 202002L using namespace numbers; #endif int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); int n, th; cin >> n >> th; vector a(n), b(n); copy_n(istream_iterator(cin), n, a.begin()); copy_n(istream_iterator(cin), n, b.begin()); vector prefa(n + 1), prefb(n + 1); for(auto i = 0; i < n; ++ i){ prefa[i + 1] = prefa[i] + a[i]; prefb[i + 1] = prefb[i] + b[i]; } long long fat = 0, res = 0; for(auto l = 0, r = 0; l < n; ++ l){ while(r < l || r < n && fat + 1LL * b[r] * (r + 1 - l) <= th){ fat += 1LL * b[r] * (r + 1 - l); ++ r; } res = max(res, prefa[r] - prefa[l]); fat -= prefb[r] - prefb[l]; } cout << res << "\n"; return 0; } /* */