結果

問題 No.2028 Even Choice
ユーザー asumo0729asumo0729
提出日時 2022-08-06 15:52:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 382 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 86,456 KB
実行使用メモリ 105,980 KB
最終ジャッジ日時 2023-10-14 16:39:04
合計ジャッジ時間 8,219 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 268 ms
96,476 KB
testcase_01 AC 249 ms
98,844 KB
testcase_02 AC 276 ms
95,112 KB
testcase_03 AC 135 ms
104,692 KB
testcase_04 AC 158 ms
105,980 KB
testcase_05 AC 163 ms
80,344 KB
testcase_06 AC 258 ms
95,132 KB
testcase_07 AC 173 ms
81,364 KB
testcase_08 AC 234 ms
88,948 KB
testcase_09 AC 219 ms
90,016 KB
testcase_10 AC 117 ms
81,620 KB
testcase_11 AC 181 ms
80,088 KB
testcase_12 AC 169 ms
78,444 KB
testcase_13 AC 188 ms
94,200 KB
testcase_14 AC 199 ms
81,440 KB
testcase_15 AC 81 ms
71,416 KB
testcase_16 AC 79 ms
71,060 KB
testcase_17 AC 82 ms
71,252 KB
testcase_18 AC 83 ms
71,344 KB
testcase_19 AC 86 ms
75,136 KB
testcase_20 AC 92 ms
75,564 KB
testcase_21 AC 89 ms
75,472 KB
testcase_22 AC 84 ms
74,968 KB
testcase_23 AC 79 ms
71,292 KB
testcase_24 AC 80 ms
71,356 KB
testcase_25 AC 78 ms
71,248 KB
testcase_26 AC 80 ms
71,160 KB
testcase_27 AC 79 ms
71,108 KB
testcase_28 AC 113 ms
88,568 KB
testcase_29 AC 105 ms
84,388 KB
testcase_30 AC 101 ms
80,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
N, K = map(int, input().split())
A = [int(a) for a in input().split()]

hq = []
heapify(hq)
s = 0
for i in range(N - K + 1, N):
    heappush(hq, A[i])
    s += A[i]

ans = -1 << 60
for i in range(N - K, -1, -1):
    if i & 1:
        ans = max(ans, s + A[i])
    s += A[i]
    heappush(hq, A[i])
    m = heappop(hq)
    s -= m
print(ans)
0