結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 280 ms
112,444 KB
testcase_01 AC 266 ms
113,576 KB
testcase_02 AC 279 ms
111,524 KB
testcase_03 AC 165 ms
115,496 KB
testcase_04 AC 167 ms
114,628 KB
testcase_05 AC 175 ms
83,540 KB
testcase_06 AC 265 ms
105,188 KB
testcase_07 AC 179 ms
86,300 KB
testcase_08 AC 227 ms
95,096 KB
testcase_09 AC 242 ms
99,440 KB
testcase_10 AC 132 ms
86,508 KB
testcase_11 AC 178 ms
81,824 KB
testcase_12 AC 133 ms
78,708 KB
testcase_13 AC 205 ms
102,872 KB
testcase_14 AC 193 ms
85,372 KB
testcase_15 AC 73 ms
71,180 KB
testcase_16 AC 74 ms
71,228 KB
testcase_17 AC 77 ms
71,136 KB
testcase_18 AC 77 ms
71,004 KB
testcase_19 AC 77 ms
71,356 KB
testcase_20 AC 84 ms
75,156 KB
testcase_21 AC 84 ms
75,472 KB
testcase_22 AC 79 ms
75,420 KB
testcase_23 AC 75 ms
71,064 KB
testcase_24 AC 74 ms
71,196 KB
testcase_25 AC 75 ms
70,944 KB
testcase_26 AC 77 ms
70,756 KB
testcase_27 AC 76 ms
70,944 KB
testcase_28 AC 116 ms
93,392 KB
testcase_29 AC 110 ms
91,392 KB
testcase_30 AC 96 ms
84,040 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