/* -*- coding: utf-8 -*- * * 2694.cc: No.2694 The Early Bird Catches The Worm - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N], bs[MAX_N]; ll ass[MAX_N + 1], bss[MAX_N + 1]; /* subroutines */ /* main */ int main() { int n, h; scanf("%d%d", &n, &h); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < n; i++) scanf("%d", bs + i); for (int i = 0; i < n; i++) ass[i + 1] = ass[i] + as[i]; for (int i = 0; i < n; i++) bss[i + 1] = bss[i] + bs[i]; ll maxx = 0, y = 0; for (int i = 0, j = 0; j < n; i++) { while (j < n && y + (ll)bs[j] * (j + 1 - i) <= h) { y += (ll)bs[j] * (j + 1 - i); j++; } maxx = max(maxx, ass[j] - ass[i]); //printf(" %d,%d: x=%lld, y=%lld\n", i, j, ass[j] - ass[i], y); y -= bss[j] - bss[i]; } printf("%lld\n", maxx); return 0; }