結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー FromBooska
提出日時 2024-03-23 16:05:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 1,172 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 162,468 KB
最終ジャッジ日時 2024-09-30 13:30:37
合計ジャッジ時間 10,906 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #

# 後ろから累積和してみたが高速計算できない
# しゃくとり法だった, ABC032C利用

N, H = map(int, input().split())
A = [0]+list(map(int, input().split()))
B = [0]+list(map(int, input().split()))

A_cumu = []
temp = 0
for a in A:
    temp += a
    A_cumu.append(temp)

B_cumu = []
temp = 0
for b in B:
    temp += b
    B_cumu.append(temp)

#print('A', A)
#print('A_cumu', A_cumu)
#print('B', B)
#print('B_cumu', B_cumu)

right = 1
left = 1
ans = 0
calc = 0
while left < N+1 and right < N+1:
    while right < N+1:
        #print('right', right, '(right+1-left)', (right+1-left))
        if calc+B[right]*(right+1-left) <= H:
            calc += B[right]*(right+1-left)
            ans = max(ans, A_cumu[right]-A_cumu[left-1])
            #print('(right+1-left)', (right+1-left), 'calc', calc, 'ans', ans)
            right += 1
        else:
            break
    #print('前', 'left', left, 'right', right, 'calc', calc, 'ans', ans)
    
    calc -= (B_cumu[right-1]-B_cumu[left-1])
    left += 1
    if left >= right:
        right = left 
        calc = 0

    #print('後', 'left', left, 'right', right, 'calc', calc, 'ans', ans)

print(ans)
0