# https://yukicoder.me/problems/no/3537 class BinaryIndexTree: """ フェニック木(BinaryIndexTree)の基本的な機能を実装したクラス """ def __init__(self, size): self.size = size self.array = [0] * (size + 1) def add(self, x, a): index = x while index <= self.size: self.array[index] += a index += index & (-index) def sum(self, x): index = x ans = 0 while index > 0: ans += self.array[index] index -= index & (-index) return ans def least_upper_bound(self, value): if self.sum(self.size) < value: return -1 elif value <= 0: return 0 m = 1 while m < self.size: m *= 2 k = 0 k_sum = 0 while m > 0: k0 = k + m if k0 < self.size: if k_sum + self.array[k0] < value: k_sum += self.array[k0] k += m m //= 2 if k < self.size: return k + 1 else: return -1 def main(): N = int(input()) B = int(input()) C = list(map(int, input().split())) S = list(map(int, input().split())) c_max = max(C) bit_count = BinaryIndexTree(c_max) bit_sum = BinaryIndexTree(c_max) for i in range(N): c = C[i] s = S[i] bit_count.add(c, s) bit_sum.add(c, c * s) # 市場操作をしないケース # この金額の商品まで全て買おうとすると「初めてBを超える商品の金額」 b_c = bit_sum.least_upper_bound(B) answer = bit_count.sum(b_c - 1) x = B - bit_sum.sum(b_c - 1) y = x // b_c answer += y # 市場操作を行うケース for i in range(N): c = C[i] s = S[i] bit_count.add(c, -s) bit_sum.add(c, -c * s) bit_count.add(1, s) bit_sum.add(1, s) b_c = bit_sum.least_upper_bound(B) ans = bit_count.sum(b_c - 1) x = B - bit_sum.sum(b_c - 1) y = x // b_c ans += y answer = max(answer ,ans) bit_count.add(1, -s) bit_sum.add(1, -s) bit_count.add(c, s) bit_sum.add(c, c * s) print(answer) if __name__ == "__main__": main()