結果
| 問題 | No.2694 The Early Bird Catches The Worm | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-03-22 21:38:42 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 250 ms / 2,000 ms | 
| コード長 | 790 bytes | 
| コンパイル時間 | 382 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 145,024 KB | 
| 最終ジャッジ日時 | 2024-09-30 11:07:35 | 
| 合計ジャッジ時間 | 18,108 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 72 | 
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
input = sys.stdin.readline
#n = int(input())
#alist = list(map(int,input().split()))
#alist = []
#s = input()
n,h = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
#https://github.com/tsutaj/pastbook-2-source-code/blob/main/python/chapter3/3-2-1.py
l, r = 0, 0
fat = 0
temp = 0
res = 0
for l in range(n):
    while r < n and fat + b[r] * (r-l+1) <= h:
        fat += b[r] * (r-l+1)
        temp += b[r]
        res += a[r]
        r += 1
    ans = max(ans, res)
    if r - l >= 1:
        fat -= temp
        temp -= b[l]
        res -= a[l]
    else:
        r += 1
print(ans)
            
            
            
        