結果

問題 No.2028 Even Choice
ユーザー lloyz
提出日時 2022-08-06 00:10:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 350 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 112,204 KB
最終ジャッジ日時 2024-09-15 22:09:34
合計ジャッジ時間 5,381 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush

n, k = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
res = 0
H = []
heapify(H)
for i in range(n - 1, -1, -1):
    if i % 2 == 1 and len(H) == k - 1:
        ans = max(ans, res + A[i])
    heappush(H, A[i])
    res += A[i]
    if len(H) == k:
        res -= heappop(H)
print(ans)
0