結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー MMMM
提出日時 2024-02-15 20:41:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 528 ms / 2,000 ms
コード長 726 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 42,492 KB
最終ジャッジ日時 2024-02-16 23:34:22
合計ジャッジ時間 22,163 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,112 KB
testcase_01 AC 29 ms
10,112 KB
testcase_02 AC 29 ms
10,112 KB
testcase_03 AC 29 ms
10,112 KB
testcase_04 AC 29 ms
10,112 KB
testcase_05 AC 29 ms
10,112 KB
testcase_06 AC 30 ms
10,240 KB
testcase_07 AC 29 ms
10,112 KB
testcase_08 AC 30 ms
10,112 KB
testcase_09 AC 30 ms
10,112 KB
testcase_10 AC 29 ms
10,112 KB
testcase_11 AC 29 ms
10,112 KB
testcase_12 AC 30 ms
10,112 KB
testcase_13 AC 30 ms
10,112 KB
testcase_14 AC 30 ms
10,112 KB
testcase_15 AC 29 ms
10,112 KB
testcase_16 AC 29 ms
10,112 KB
testcase_17 AC 32 ms
10,112 KB
testcase_18 AC 30 ms
10,112 KB
testcase_19 AC 29 ms
10,112 KB
testcase_20 AC 30 ms
10,112 KB
testcase_21 AC 29 ms
10,112 KB
testcase_22 AC 29 ms
10,112 KB
testcase_23 AC 30 ms
10,112 KB
testcase_24 AC 162 ms
18,080 KB
testcase_25 AC 122 ms
17,560 KB
testcase_26 AC 175 ms
19,416 KB
testcase_27 AC 239 ms
22,996 KB
testcase_28 AC 211 ms
24,676 KB
testcase_29 AC 81 ms
15,280 KB
testcase_30 AC 340 ms
33,480 KB
testcase_31 AC 210 ms
23,164 KB
testcase_32 AC 443 ms
34,700 KB
testcase_33 AC 382 ms
34,168 KB
testcase_34 AC 43 ms
11,264 KB
testcase_35 AC 195 ms
22,028 KB
testcase_36 AC 281 ms
25,696 KB
testcase_37 AC 426 ms
36,976 KB
testcase_38 AC 255 ms
29,192 KB
testcase_39 AC 76 ms
14,352 KB
testcase_40 AC 197 ms
23,144 KB
testcase_41 AC 107 ms
16,328 KB
testcase_42 AC 35 ms
10,624 KB
testcase_43 AC 57 ms
12,032 KB
testcase_44 AC 364 ms
39,288 KB
testcase_45 AC 317 ms
39,280 KB
testcase_46 AC 144 ms
18,680 KB
testcase_47 AC 123 ms
18,512 KB
testcase_48 AC 265 ms
24,684 KB
testcase_49 AC 527 ms
22,168 KB
testcase_50 AC 516 ms
22,188 KB
testcase_51 AC 511 ms
22,168 KB
testcase_52 AC 524 ms
22,176 KB
testcase_53 AC 512 ms
22,068 KB
testcase_54 AC 478 ms
42,492 KB
testcase_55 AC 472 ms
42,492 KB
testcase_56 AC 439 ms
42,492 KB
testcase_57 AC 525 ms
42,492 KB
testcase_58 AC 400 ms
42,492 KB
testcase_59 AC 496 ms
42,492 KB
testcase_60 AC 491 ms
42,492 KB
testcase_61 AC 526 ms
42,492 KB
testcase_62 AC 518 ms
42,492 KB
testcase_63 AC 488 ms
42,492 KB
testcase_64 AC 380 ms
42,492 KB
testcase_65 AC 486 ms
42,492 KB
testcase_66 AC 461 ms
42,492 KB
testcase_67 AC 403 ms
42,492 KB
testcase_68 AC 377 ms
42,492 KB
testcase_69 AC 528 ms
32,424 KB
testcase_70 AC 518 ms
32,424 KB
testcase_71 AC 526 ms
32,424 KB
testcase_72 AC 507 ms
32,424 KB
testcase_73 AC 511 ms
32,424 KB
testcase_74 AC 262 ms
21,208 KB
testcase_75 AC 514 ms
32,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0