#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll N, H, ans=0; cin >> N >> H; vector A(N+1), B(N+1), SA(N+1), SB(N+1), SC(N+1); for (int i=1; i<=N; i++){ cin >> A[i]; SA[i] = SA[i-1] + A[i]; } for (int i=1; i<=N; i++){ cin >> B[i]; SB[i] = SB[i-1] + B[i]; SC[i] = SC[i-1] + B[i]*i; } for (int i=1; i<=N; i++){ if (B[i] > H) continue; ll ok=i, ng=N+1; while (ng-ok > 1){ ll mid = (ok+ng)/2; if (SC[mid] - SC[i-1] - (SB[mid]-SB[i-1]) * (i-1) <= H){ ok = mid; } else { ng = mid; } } //cout << i << " " << ok << " " << SC[ok] - SC[i-1] - (SB[ok]-SB[i-1]) *(i-1) << " " << SA[ok]-SA[i-1] << endl; ans = max(ans, SA[ok]-SA[i-1]); } cout << ans << endl; return 0; }