結果

問題 No.2028 Even Choice
ユーザー rlangevinrlangevin
提出日時 2023-01-20 20:49:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 328 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 87,344 KB
実行使用メモリ 119,108 KB
最終ジャッジ日時 2023-09-05 13:03:30
合計ジャッジ時間 8,140 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 277 ms
105,936 KB
testcase_01 AC 256 ms
106,240 KB
testcase_02 AC 283 ms
106,224 KB
testcase_03 AC 138 ms
117,384 KB
testcase_04 AC 164 ms
119,108 KB
testcase_05 AC 170 ms
82,576 KB
testcase_06 AC 264 ms
100,492 KB
testcase_07 AC 172 ms
84,480 KB
testcase_08 AC 243 ms
95,824 KB
testcase_09 AC 236 ms
94,868 KB
testcase_10 AC 119 ms
84,444 KB
testcase_11 AC 183 ms
81,504 KB
testcase_12 AC 158 ms
78,728 KB
testcase_13 AC 199 ms
99,296 KB
testcase_14 AC 198 ms
84,516 KB
testcase_15 AC 74 ms
71,316 KB
testcase_16 AC 73 ms
71,452 KB
testcase_17 AC 73 ms
71,444 KB
testcase_18 AC 76 ms
71,672 KB
testcase_19 AC 80 ms
75,340 KB
testcase_20 AC 86 ms
75,868 KB
testcase_21 AC 84 ms
75,488 KB
testcase_22 AC 80 ms
75,672 KB
testcase_23 AC 75 ms
71,324 KB
testcase_24 AC 75 ms
71,480 KB
testcase_25 AC 74 ms
71,496 KB
testcase_26 AC 75 ms
71,412 KB
testcase_27 AC 76 ms
71,408 KB
testcase_28 AC 112 ms
95,912 KB
testcase_29 AC 103 ms
89,928 KB
testcase_30 AC 95 ms
83,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

N, K = map(int, input().split())
A = list(map(int, input().split()))
H = []
A.reverse()
ans = 0
val = 0
for i in range(N):
    if i % 2 == N % 2:
        if len(H) == K - 1:
            ans = max(ans, val + A[i])
    heappush(H, A[i])
    val += A[i]
    if len(H) == K:
        val -= heappop(H)
print(ans)
0