結果

問題 No.2028 Even Choice
ユーザー H3PO4H3PO4
提出日時 2022-08-05 21:58:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 463 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 115,760 KB
最終ジャッジ日時 2023-10-13 22:46:21
合計ジャッジ時間 6,288 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 278 ms
112,528 KB
testcase_01 AC 261 ms
113,568 KB
testcase_02 AC 272 ms
111,828 KB
testcase_03 AC 157 ms
115,760 KB
testcase_04 AC 160 ms
115,192 KB
testcase_05 AC 169 ms
83,884 KB
testcase_06 AC 258 ms
105,520 KB
testcase_07 AC 173 ms
86,688 KB
testcase_08 AC 219 ms
95,416 KB
testcase_09 AC 234 ms
99,504 KB
testcase_10 AC 126 ms
87,012 KB
testcase_11 AC 172 ms
82,172 KB
testcase_12 AC 131 ms
78,676 KB
testcase_13 AC 197 ms
103,104 KB
testcase_14 AC 191 ms
85,856 KB
testcase_15 AC 72 ms
71,540 KB
testcase_16 AC 73 ms
71,492 KB
testcase_17 AC 72 ms
71,388 KB
testcase_18 AC 73 ms
71,360 KB
testcase_19 AC 72 ms
71,404 KB
testcase_20 AC 80 ms
75,628 KB
testcase_21 AC 79 ms
75,896 KB
testcase_22 AC 77 ms
75,652 KB
testcase_23 AC 73 ms
71,236 KB
testcase_24 AC 71 ms
71,284 KB
testcase_25 AC 73 ms
71,108 KB
testcase_26 AC 73 ms
71,112 KB
testcase_27 AC 71 ms
71,348 KB
testcase_28 AC 117 ms
93,416 KB
testcase_29 AC 106 ms
91,484 KB
testcase_30 AC 91 ms
84,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

N, K = map(int, input().split())
A = tuple(map(int, input().split()))

r = (N - K - 1) // 2 * 2 + 1
h = list(A[r + 1:])
heapq.heapify(h)
while len(h) >= K:
    heapq.heappop(h)
s = sum(h)
ans = 0
for i in range(r, -1, -2):
    ans = max(ans, s + A[i])
    if i >= 0:
        p = heapq.heappushpop(h, A[i])
        s += A[i]
        s -= p
    if i - 1 >= 0:
        p = heapq.heappushpop(h, A[i - 1])
        s += A[i - 1]
        s -= p
print(ans)
0