if __name__ == "__main__": n, w = map(int, input().strip().split()) z = list(map(int, input().strip().split())) t = list(map(int, input().strip().split())) p = 0 i = 0 record = [] pre = -1 ans = 0 while True and i<n: if p+z[i]<=w: p += z[i] record.append([z[i], t[i]]) i += 1 else: record = sorted(record, key=lambda x: x[1]) pre = record[0][1] p -= record[0][0] ans += pre record = record[1:] while record and pre==record[0][1]: p -= record[0][0] record = record[1:] if record: record = [[x[0], x[1]-pre] for x in record] if record: ans += max([x[1] for x in record]) print(ans) 第一题咋做啊