結果
| 問題 | No.2694 The Early Bird Catches The Worm |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2024-03-23 00:38:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 263 ms / 2,000 ms |
| コード長 | 1,695 bytes |
| コンパイル時間 | 200 ms |
| コンパイル使用メモリ | 82,576 KB |
| 実行使用メモリ | 147,564 KB |
| 最終ジャッジ日時 | 2024-09-30 12:51:50 |
| 合計ジャッジ時間 | 13,510 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 72 |
ソースコード
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 can_append(self, a, b) -> bool:
s = self.s + b * (len(self.q) + 1)
return s <= H
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
return res.can_append(a, b)
# 伸ばす(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)
norioc