結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー MM
提出日時 2024-09-15 16:38:25
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 732 ms / 2,000 ms
コード長 802 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 59,776 KB
最終ジャッジ日時 2024-09-15 16:38:57
合計ジャッジ時間 31,299 ms
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #

N, H = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_cumsum = [0] * (N + 1)
B_cumsum = [0] * (N + 1)
B_cumsum_weighted = [0] * (N + 1)

for i in range(1, N + 1):
    A_cumsum[i] = A_cumsum[i - 1] + A[i - 1]
    B_cumsum[i] = B_cumsum[i - 1] + B[i - 1]
    B_cumsum_weighted[i] = B_cumsum_weighted[i - 1] + i * B[i - 1]

max_satisfaction = 0
L = 1

for R in range(1, N + 1):
    while L <= R:
        fatigue = (B_cumsum_weighted[R] - B_cumsum_weighted[L - 1]) - (L - 1) * (B_cumsum[R] - B_cumsum[L - 1])
        if fatigue <= H:
            break
        L += 1
    if L > R:
        continue
    satisfaction = A_cumsum[R] - A_cumsum[L - 1]
    if satisfaction > max_satisfaction:
        max_satisfaction = satisfaction

print(max_satisfaction)
0