結果

問題 No.2028 Even Choice
ユーザー KudeKude
提出日時 2022-08-05 21:32:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 340 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 86,816 KB
実行使用メモリ 117,036 KB
最終ジャッジ日時 2023-10-13 22:03:58
合計ジャッジ時間 6,234 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 224 ms
110,256 KB
testcase_01 AC 216 ms
110,468 KB
testcase_02 AC 218 ms
110,336 KB
testcase_03 AC 138 ms
117,036 KB
testcase_04 AC 141 ms
115,504 KB
testcase_05 AC 137 ms
82,860 KB
testcase_06 AC 211 ms
104,704 KB
testcase_07 AC 143 ms
85,736 KB
testcase_08 AC 185 ms
94,076 KB
testcase_09 AC 186 ms
98,048 KB
testcase_10 AC 111 ms
85,500 KB
testcase_11 AC 134 ms
82,192 KB
testcase_12 AC 127 ms
78,884 KB
testcase_13 AC 176 ms
100,328 KB
testcase_14 AC 143 ms
85,256 KB
testcase_15 AC 73 ms
71,348 KB
testcase_16 AC 72 ms
70,852 KB
testcase_17 AC 73 ms
70,860 KB
testcase_18 AC 73 ms
71,292 KB
testcase_19 AC 74 ms
71,288 KB
testcase_20 AC 81 ms
75,304 KB
testcase_21 AC 80 ms
75,444 KB
testcase_22 AC 78 ms
75,300 KB
testcase_23 AC 73 ms
71,068 KB
testcase_24 AC 72 ms
71,064 KB
testcase_25 AC 74 ms
71,212 KB
testcase_26 AC 73 ms
71,288 KB
testcase_27 AC 72 ms
71,248 KB
testcase_28 AC 114 ms
93,168 KB
testcase_29 AC 101 ms
91,740 KB
testcase_30 AC 91 ms
83,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappushpop
n, k = map(int, input().split())
sm = 0
q = []
ans = 0
for i, x in reversed(list(enumerate(map(int, input().split()), 1))):
    if len(q) < k - 1:
        heappush(q, x)
        sm += x
    else:
        if i % 2 == 0:
            ans = max(ans, sm + x)
        sm += x - heappushpop(q, x)
print(ans)
0