#include using namespace std; int main() { int n, h; cin >> n >> h; vector a(n + 1), b(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } vector s(n + 1); for (int i = 1; i <= n; i++) { s[i] = s[i - 1] + b[i]; } int r = 0; long long ans = 0LL, sat = 0LL, fat = 0LL; for (int l = 1; l <= n; l++) { //cout << "l = " << l << endl; if (l >= 2) { sat -= a[l - 1]; fat -= s[r] - s[l - 2]; } //cout << r << " " << sat << " " << fat << endl; while (r <= n && fat <= h) { r++; sat += a[r]; fat += (long long)(r - l + 1) * b[r]; } //cout << r << " " << sat << " " << fat << endl; ans = max(ans, sat - a[r]); } cout << ans << endl; }