結果

問題 No.2028 Even Choice
ユーザー 👑 rin204
提出日時 2022-08-20 15:19:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 302 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 112,308 KB
最終ジャッジ日時 2024-10-09 08:01:49
合計ジャッジ時間 6,242 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, k = map(int, input().split())
A = list(map(int, input().split()))
tot = 0
hq = []
ans = 0
for i in range(n - 1, -1, -1):
    a = A[i]
    tot += a
    heappush(hq, a)
    if len(hq) == k:
        if i & 1:
            ans = max(ans, tot)
        tot -= heappop(hq)
print(ans)


0