結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,608 KB
testcase_01 AC 40 ms
55,608 KB
testcase_02 AC 40 ms
55,608 KB
testcase_03 AC 42 ms
55,608 KB
testcase_04 AC 42 ms
55,608 KB
testcase_05 AC 43 ms
55,608 KB
testcase_06 AC 50 ms
63,628 KB
testcase_07 AC 43 ms
55,608 KB
testcase_08 AC 47 ms
61,576 KB
testcase_09 AC 46 ms
55,608 KB
testcase_10 AC 44 ms
55,608 KB
testcase_11 AC 43 ms
55,608 KB
testcase_12 AC 43 ms
55,608 KB
testcase_13 AC 42 ms
55,608 KB
testcase_14 AC 45 ms
55,608 KB
testcase_15 AC 43 ms
55,608 KB
testcase_16 AC 45 ms
55,608 KB
testcase_17 AC 44 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 42 ms
55,608 KB
testcase_23 AC 44 ms
55,608 KB
testcase_24 AC 143 ms
90,704 KB
testcase_25 AC 152 ms
91,024 KB
testcase_26 AC 170 ms
92,188 KB
testcase_27 AC 180 ms
98,484 KB
testcase_28 AC 205 ms
103,320 KB
testcase_29 AC 88 ms
84,176 KB
testcase_30 AC 208 ms
118,072 KB
testcase_31 AC 192 ms
98,976 KB
testcase_32 AC 231 ms
118,204 KB
testcase_33 AC 240 ms
118,688 KB
testcase_34 AC 108 ms
77,656 KB
testcase_35 AC 164 ms
95,000 KB
testcase_36 AC 198 ms
106,632 KB
testcase_37 AC 279 ms
141,760 KB
testcase_38 AC 180 ms
109,024 KB
testcase_39 AC 102 ms
82,632 KB
testcase_40 AC 176 ms
98,936 KB
testcase_41 AC 176 ms
87,888 KB
testcase_42 AC 54 ms
66,336 KB
testcase_43 AC 115 ms
77,980 KB
testcase_44 AC 224 ms
142,328 KB
testcase_45 AC 164 ms
141,940 KB
testcase_46 AC 156 ms
91,660 KB
testcase_47 AC 105 ms
90,048 KB
testcase_48 AC 201 ms
103,436 KB
testcase_49 AC 258 ms
129,780 KB
testcase_50 AC 247 ms
129,776 KB
testcase_51 AC 239 ms
129,780 KB
testcase_52 AC 242 ms
129,776 KB
testcase_53 AC 280 ms
129,816 KB
testcase_54 AC 281 ms
143,048 KB
testcase_55 AC 249 ms
142,920 KB
testcase_56 AC 295 ms
143,048 KB
testcase_57 AC 258 ms
142,916 KB
testcase_58 AC 228 ms
142,916 KB
testcase_59 AC 281 ms
143,048 KB
testcase_60 AC 252 ms
142,920 KB
testcase_61 AC 261 ms
142,920 KB
testcase_62 AC 287 ms
142,916 KB
testcase_63 AC 289 ms
143,048 KB
testcase_64 AC 209 ms
142,920 KB
testcase_65 AC 268 ms
143,044 KB
testcase_66 AC 266 ms
143,044 KB
testcase_67 AC 251 ms
142,920 KB
testcase_68 AC 202 ms
142,916 KB
testcase_69 AC 225 ms
147,140 KB
testcase_70 AC 224 ms
147,144 KB
testcase_71 AC 226 ms
147,016 KB
testcase_72 AC 243 ms
146,500 KB
testcase_73 AC 225 ms
147,012 KB
testcase_74 AC 154 ms
98,972 KB
testcase_75 AC 225 ms
147,140 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):
        assert self.s <= H
        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 を一つ進める
        if lo <= hi:
            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):
    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