結果

問題 No.2028 Even Choice
ユーザー ニックネームニックネーム
提出日時 2022-08-05 22:42:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 467 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 10,772 KB
実行使用メモリ 30,092 KB
最終ジャッジ日時 2023-10-14 00:13:56
合計ジャッジ時間 5,592 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 349 ms
30,092 KB
testcase_01 AC 279 ms
29,984 KB
testcase_02 AC 393 ms
29,928 KB
testcase_03 AC 172 ms
30,036 KB
testcase_04 AC 212 ms
29,956 KB
testcase_05 AC 69 ms
12,812 KB
testcase_06 AC 342 ms
27,932 KB
testcase_07 AC 79 ms
13,744 KB
testcase_08 AC 268 ms
21,736 KB
testcase_09 AC 213 ms
24,216 KB
testcase_10 AC 60 ms
13,924 KB
testcase_11 AC 80 ms
11,944 KB
testcase_12 AC 44 ms
9,868 KB
testcase_13 AC 154 ms
25,232 KB
testcase_14 AC 121 ms
14,228 KB
testcase_15 AC 16 ms
8,112 KB
testcase_16 AC 16 ms
7,920 KB
testcase_17 AC 16 ms
8,048 KB
testcase_18 AC 17 ms
8,120 KB
testcase_19 AC 17 ms
8,052 KB
testcase_20 AC 18 ms
7,932 KB
testcase_21 AC 17 ms
7,996 KB
testcase_22 AC 17 ms
7,992 KB
testcase_23 RE -
testcase_24 AC 16 ms
7,952 KB
testcase_25 RE -
testcase_26 AC 16 ms
7,872 KB
testcase_27 AC 17 ms
8,016 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
n, k = map(int, input().split())
a = list(map(int, input().split()))
hq = []
s = 0
ans = 0
for i in range(n-1, -1, -1):
    if len(hq) < k-1:
        heappush(hq, a[i])
        s += a[i]
    elif i%2 == 0:
        m = heappop(hq)
        heappush(hq, max(a[i], m))
        s += max(a[i], m)-m
    else:
        ans = max(ans, a[i]+s)
        m = heappop(hq)
        heappush(hq, max(a[i], m))
        s += max(a[i], m)-m
print(ans)
0