結果

問題 No.2028 Even Choice
ユーザー hirakuhiraku
提出日時 2022-08-05 22:13:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 543 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 118,852 KB
最終ジャッジ日時 2023-10-13 23:20:36
合計ジャッジ時間 5,941 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 229 ms
106,212 KB
testcase_01 AC 217 ms
106,268 KB
testcase_02 AC 241 ms
106,512 KB
testcase_03 AC 134 ms
117,124 KB
testcase_04 AC 149 ms
118,852 KB
testcase_05 AC 143 ms
82,252 KB
testcase_06 AC 228 ms
101,020 KB
testcase_07 AC 147 ms
84,324 KB
testcase_08 AC 209 ms
95,432 KB
testcase_09 AC 198 ms
94,624 KB
testcase_10 AC 112 ms
84,284 KB
testcase_11 AC 153 ms
81,324 KB
testcase_12 AC 137 ms
78,160 KB
testcase_13 AC 178 ms
97,180 KB
testcase_14 AC 164 ms
84,244 KB
testcase_15 AC 67 ms
71,568 KB
testcase_16 AC 68 ms
71,336 KB
testcase_17 AC 72 ms
71,200 KB
testcase_18 AC 72 ms
71,312 KB
testcase_19 AC 79 ms
75,436 KB
testcase_20 AC 84 ms
75,892 KB
testcase_21 AC 78 ms
75,736 KB
testcase_22 AC 79 ms
75,524 KB
testcase_23 AC 71 ms
71,340 KB
testcase_24 AC 70 ms
71,288 KB
testcase_25 AC 70 ms
71,248 KB
testcase_26 AC 69 ms
71,060 KB
testcase_27 AC 70 ms
71,288 KB
testcase_28 AC 110 ms
95,632 KB
testcase_29 AC 98 ms
89,432 KB
testcase_30 AC 92 ms
83,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop


n, k = map(int, input().split())
A = list(map(int, input().split()))

# kが1の場合は2~n枚目の偶数枚目の最大値
# kが2以上の場合は左端lが偶数枚目、残りのk-1枚はlより右側の大きいものから順に
ans = 0
rui = 0
stack = []
for i in range(n - 1, 0, -1):
    heappush(stack, A[i])
    rui += A[i]
    if len(stack) >= k:
        s = heappop(stack)
        rui -= s
    if (i - 1) % 2 == 1:
        ans = max(ans, A[i - 1] + rui)
    # print(stack, ans)

print(ans)
0