結果

問題 No.2028 Even Choice
ユーザー ニックネーム
提出日時 2022-08-05 22:42:35
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 467 bytes
コンパイル時間 919 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 33,108 KB
最終ジャッジ日時 2024-09-15 20:06:15
合計ジャッジ時間 6,331 ms
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 RE * 5
権限があれば一括ダウンロードができます

ソースコード

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