結果
| 問題 |
No.2694 The Early Bird Catches The Worm
|
| コンテスト | |
| ユーザー |
MM
|
| 提出日時 | 2024-02-15 20:41:08 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 541 ms / 2,000 ms |
| コード長 | 726 bytes |
| コンパイル時間 | 130 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 41,332 KB |
| 最終ジャッジ日時 | 2024-09-28 22:30:50 |
| 合計ジャッジ時間 | 21,037 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 72 |
ソースコード
N, H = map(int, input().split()) # Reading N and H
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# Prepare cumulative sum of B
S = [0] * (N + 1)
for i in range(N):
S[i + 1] = S[i] + B[i]
# Solve using sliding window method
ans = 0
tmp = 0
need_hp = 0
r = 0
for l in range(N):
while r < N and need_hp + B[r] * (r - l + 1) <= H:
tmp += A[r]
need_hp += B[r] * (r - l + 1)
r += 1
# Debugging output (optional)
# print(l, r, need_hp, tmp)
# Changing Maximum
ans = max(ans, tmp)
# Preparing for incrementing l
if l == r:
r += 1
else:
tmp -= A[l]
need_hp -= S[r] - S[l] # Cumulative sum for O(1) update
# Output
print(ans)
MM