結果

問題 No.2028 Even Choice
ユーザー ニックネームニックネーム
提出日時 2022-08-05 22:48:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 506 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 30,124 KB
最終ジャッジ日時 2023-10-14 00:23:13
合計ジャッジ時間 5,391 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 362 ms
30,124 KB
testcase_01 AC 284 ms
29,992 KB
testcase_02 AC 400 ms
29,936 KB
testcase_03 AC 171 ms
29,928 KB
testcase_04 AC 212 ms
29,928 KB
testcase_05 AC 70 ms
12,836 KB
testcase_06 AC 354 ms
27,704 KB
testcase_07 AC 80 ms
13,824 KB
testcase_08 AC 264 ms
21,656 KB
testcase_09 AC 218 ms
24,080 KB
testcase_10 AC 60 ms
13,740 KB
testcase_11 AC 82 ms
12,008 KB
testcase_12 AC 44 ms
9,728 KB
testcase_13 AC 159 ms
25,320 KB
testcase_14 AC 123 ms
14,144 KB
testcase_15 AC 17 ms
7,968 KB
testcase_16 AC 17 ms
8,048 KB
testcase_17 AC 17 ms
8,132 KB
testcase_18 AC 18 ms
8,048 KB
testcase_19 AC 17 ms
8,040 KB
testcase_20 AC 18 ms
7,972 KB
testcase_21 AC 18 ms
8,416 KB
testcase_22 AC 18 ms
8,044 KB
testcase_23 AC 17 ms
8,196 KB
testcase_24 AC 17 ms
8,020 KB
testcase_25 AC 17 ms
8,312 KB
testcase_26 AC 16 ms
8,004 KB
testcase_27 AC 16 ms
8,148 KB
testcase_28 AC 60 ms
22,400 KB
testcase_29 AC 45 ms
17,320 KB
testcase_30 AC 35 ms
14,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
n, k = map(int, input().split())
a = list(map(int, input().split()))
if k == 1: print(max(a[1::2])); exit()
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