結果

問題 No.2028 Even Choice
ユーザー asumo0729
提出日時 2022-08-06 15:52:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 382 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 100,292 KB
最終ジャッジ日時 2024-09-16 10:58:24
合計ジャッジ時間 5,032 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
N, K = map(int, input().split())
A = [int(a) for a in input().split()]

hq = []
heapify(hq)
s = 0
for i in range(N - K + 1, N):
    heappush(hq, A[i])
    s += A[i]

ans = -1 << 60
for i in range(N - K, -1, -1):
    if i & 1:
        ans = max(ans, s + A[i])
    s += A[i]
    heappush(hq, A[i])
    m = heappop(hq)
    s -= m
print(ans)
0