use std::io::{self, Read}; use std::str::FromStr; fn main() { let mut input = String::new(); io::stdin().read_to_string(&mut input).unwrap(); let mut iter = input.split_whitespace(); let n: usize = iter.next().unwrap().parse().unwrap(); let h: i64 = iter.next().unwrap().parse().unwrap(); let a: Vec = (0..n) .map(|_| iter.next().unwrap().parse().unwrap()) .collect(); let b: Vec = (0..n) .map(|_| iter.next().unwrap().parse().unwrap()) .collect(); let mut s: Vec = vec![0; n + 1]; for i in 0..n { s[i + 1] = s[i] + b[i]; } let mut ans = 0; let mut tmp = 0; let mut need_hp = 0; let mut r = 0; for l in 0..n { while r < n && need_hp + b[r] * (r as i64 - l as i64 + 1) <= h { tmp += a[r]; need_hp += b[r] * (r as i64 - l as i64 + 1); r += 1; } // println!("{} {} {} {}", l, r, need_hp, tmp); if tmp > ans { ans = tmp; } if l == r { r += 1; } else { tmp -= a[l]; need_hp -= s[r] - s[l]; } } println!("{}", ans); }