結果

問題 No.2028 Even Choice
ユーザー lloyzlloyz
提出日時 2022-08-06 00:10:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 350 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 86,752 KB
実行使用メモリ 118,640 KB
最終ジャッジ日時 2023-10-14 02:28:56
合計ジャッジ時間 6,481 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 273 ms
105,504 KB
testcase_01 AC 261 ms
105,668 KB
testcase_02 AC 283 ms
105,820 KB
testcase_03 AC 138 ms
116,992 KB
testcase_04 AC 165 ms
118,640 KB
testcase_05 AC 167 ms
82,496 KB
testcase_06 AC 265 ms
100,216 KB
testcase_07 AC 172 ms
84,072 KB
testcase_08 AC 238 ms
95,376 KB
testcase_09 AC 237 ms
94,472 KB
testcase_10 AC 123 ms
84,152 KB
testcase_11 AC 179 ms
81,200 KB
testcase_12 AC 157 ms
78,216 KB
testcase_13 AC 196 ms
98,924 KB
testcase_14 AC 196 ms
84,004 KB
testcase_15 AC 72 ms
71,232 KB
testcase_16 AC 74 ms
71,188 KB
testcase_17 AC 75 ms
71,068 KB
testcase_18 AC 76 ms
71,116 KB
testcase_19 AC 80 ms
75,068 KB
testcase_20 AC 84 ms
75,604 KB
testcase_21 AC 84 ms
75,276 KB
testcase_22 AC 82 ms
75,044 KB
testcase_23 AC 74 ms
70,876 KB
testcase_24 AC 76 ms
71,188 KB
testcase_25 AC 75 ms
70,992 KB
testcase_26 AC 75 ms
71,188 KB
testcase_27 AC 73 ms
70,808 KB
testcase_28 AC 113 ms
95,268 KB
testcase_29 AC 101 ms
89,476 KB
testcase_30 AC 95 ms
83,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush

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

ans = 0
res = 0
H = []
heapify(H)
for i in range(n - 1, -1, -1):
    if i % 2 == 1 and len(H) == k - 1:
        ans = max(ans, res + A[i])
    heappush(H, A[i])
    res += A[i]
    if len(H) == k:
        res -= heappop(H)
print(ans)
0