結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー Theta
提出日時 2024-04-24 13:31:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 1,115 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 154,336 KB
最終ジャッジ日時 2024-11-06 21:42:37
合計ジャッジ時間 13,948 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate
import sys


def printe(*args, end="\n", **kwargs):
    print(*args, end=end, file=sys.stderr, **kwargs)


def main():
    N, H = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    A_accum = list(accumulate(A))
    B_accum = list(accumulate(B, initial=0))

    max_satisfied = 0
    L = 0
    R = 0
    cur_tired = 0
    cur_satisfied = 0
    while L < N:

        if R == N:
            max_satisfied = max(max_satisfied, cur_satisfied)
            break
        if cur_tired + B[R] * (R - L + 1) <= H:
            cur_tired += B[R] * (R - L + 1)
            cur_satisfied += A[R]
            R += 1
            continue

        max_satisfied = max(max_satisfied, cur_satisfied)
        if L < R:
            cur_satisfied -= A[L]
            cur_tired -= B_accum[R] - B_accum[L]
            L += 1
        else:
            L += 1
            R += 1
        # cur_satisfied += A[R]

        # cur_tired += B[R] * (R - L)
        # R += 1
        # L += 1
    print(max_satisfied)


if __name__ == "__main__":
    main()
0