結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー noriocnorioc
提出日時 2024-03-23 00:28:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 1,619 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 147,148 KB
最終ジャッジ日時 2024-03-23 00:28:19
合計ジャッジ時間 16,018 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,608 KB
testcase_01 AC 40 ms
55,608 KB
testcase_02 AC 42 ms
55,608 KB
testcase_03 AC 42 ms
55,608 KB
testcase_04 AC 42 ms
55,608 KB
testcase_05 AC 41 ms
55,608 KB
testcase_06 AC 50 ms
63,628 KB
testcase_07 AC 42 ms
55,608 KB
testcase_08 AC 49 ms
61,576 KB
testcase_09 AC 45 ms
55,608 KB
testcase_10 AC 45 ms
55,608 KB
testcase_11 AC 45 ms
55,608 KB
testcase_12 AC 42 ms
55,608 KB
testcase_13 AC 42 ms
55,608 KB
testcase_14 AC 44 ms
55,608 KB
testcase_15 AC 43 ms
55,608 KB
testcase_16 AC 45 ms
55,608 KB
testcase_17 AC 43 ms
55,608 KB
testcase_18 AC 45 ms
57,668 KB
testcase_19 AC 42 ms
55,608 KB
testcase_20 AC 43 ms
55,608 KB
testcase_21 AC 41 ms
55,608 KB
testcase_22 AC 43 ms
55,608 KB
testcase_23 AC 45 ms
55,608 KB
testcase_24 AC 147 ms
90,448 KB
testcase_25 AC 155 ms
91,024 KB
testcase_26 AC 170 ms
92,188 KB
testcase_27 AC 194 ms
98,564 KB
testcase_28 AC 183 ms
103,316 KB
testcase_29 AC 91 ms
84,176 KB
testcase_30 AC 227 ms
118,188 KB
testcase_31 AC 190 ms
98,976 KB
testcase_32 AC 231 ms
118,212 KB
testcase_33 AC 268 ms
118,692 KB
testcase_34 AC 108 ms
77,664 KB
testcase_35 AC 162 ms
94,992 KB
testcase_36 AC 202 ms
106,636 KB
testcase_37 AC 270 ms
141,768 KB
testcase_38 AC 177 ms
109,024 KB
testcase_39 AC 105 ms
82,632 KB
testcase_40 AC 201 ms
98,932 KB
testcase_41 AC 162 ms
87,888 KB
testcase_42 AC 54 ms
66,332 KB
testcase_43 AC 126 ms
78,108 KB
testcase_44 AC 225 ms
142,332 KB
testcase_45 AC 169 ms
141,944 KB
testcase_46 AC 158 ms
91,660 KB
testcase_47 AC 115 ms
89,920 KB
testcase_48 AC 214 ms
103,436 KB
testcase_49 AC 251 ms
129,776 KB
testcase_50 AC 251 ms
129,776 KB
testcase_51 AC 247 ms
129,776 KB
testcase_52 AC 246 ms
129,772 KB
testcase_53 AC 262 ms
129,812 KB
testcase_54 AC 261 ms
142,920 KB
testcase_55 AC 293 ms
143,048 KB
testcase_56 AC 278 ms
143,048 KB
testcase_57 AC 275 ms
142,916 KB
testcase_58 AC 225 ms
142,916 KB
testcase_59 AC 287 ms
143,052 KB
testcase_60 AC 252 ms
142,920 KB
testcase_61 AC 263 ms
142,920 KB
testcase_62 AC 276 ms
142,920 KB
testcase_63 AC 297 ms
143,048 KB
testcase_64 AC 229 ms
142,920 KB
testcase_65 AC 293 ms
143,048 KB
testcase_66 AC 294 ms
143,044 KB
testcase_67 AC 275 ms
143,052 KB
testcase_68 AC 209 ms
142,916 KB
testcase_69 AC 229 ms
147,140 KB
testcase_70 AC 229 ms
147,148 KB
testcase_71 AC 236 ms
147,016 KB
testcase_72 AC 237 ms
146,504 KB
testcase_73 AC 226 ms
147,012 KB
testcase_74 AC 155 ms
98,968 KB
testcase_75 AC 228 ms
147,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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


class D:
    def __init__(self):
        self.q = deque()
        self.a = 0
        self.b = 0
        self.s = 0

    def append(self, a, b):
        self.s += b * (len(self.q) + 1)
        self.q.append((a, b))
        self.a += a
        self.b += b

    def popleft(self):
        self.s -= self.b
        a, b = self.q.popleft()
        self.a -= a
        self.b -= b

    def score(self):
        if self.s > H: return 0
        return self.a


# a : 入力リスト
# pred : 条件
# op : 右端を伸ばす演算
# invop : 左端を縮める演算
def shakutori(a: list, pred, op, invop, identity):
    n = len(a)
    res = identity()
    hi = -1
    for lo in range(n):
        if lo > hi:
            hi = lo - 1
            res = identity()

        # 必要な分だけ伸ばす
        while hi+1 < n and pred(res, a[hi+1]):
            res = op(res, a[hi+1])
            hi += 1

        if lo <= hi:
            yield res, lo, hi

        # lo を一つ進める
        res = invop(res, a[lo])


# res に x を追加できるか
def pred(res: D, x):
    a, b = x
    s = res.s + b * (len(res.q) + 1)
    return s <= H


# 伸ばす(res に x を追加)
def op(res: D, x):
    a, b = x
    res.append(a, b)
    return res


# 縮める(res から x を削除)
def invop(res: D, x):
    if len(res.q) > 0:
        res.popleft()
    return res


ans = 0
for res, lo, hi in shakutori(list(zip(A, B)), pred, op, invop, D):
    ans = max(ans, res.score())

print(ans)
0