#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef unsigned long long ull; typedef long long ll; #define REP(i,n) for(int (i) = 0; (i) < (n); ++(i)) #define FOR(i,a,b) for(int (i) = a; (i) < (b); ++(i)) int a[200010]; int b[200010]; int main () { int n, h; cin >> n >> h; REP(i,n) cin >> a[i]; REP(i,n) cin >> b[i]; int j = 0; ll hard = 0; ll best = 0; ll ans = 0; ll sum = 0; REP(i,n) { if (j < i) { j = i; hard = 0; best = 0; sum = 0; } while (j < n) { ll nxt = ll(j-i+1) * b[j]; if (hard + nxt <= h) { hard += nxt; best += a[j]; sum += b[j]; ++j; } else break; } if (j > i) { ans = max(ans, best); sum -= b[i]; hard -= b[i]; hard -= sum; best -= a[i]; } } cout << ans << endl; }