結果

問題 No.2028 Even Choice
コンテスト
ユーザー asumo0729
提出日時 2022-08-06 12:27:30
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 145 ms / 2,000 ms
+ 952µs
コード長 464 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 88 ms
コンパイル使用メモリ 64,776 KB
実行使用メモリ 90,856 KB
最終ジャッジ日時 2026-10-16 15:56:01
合計ジャッジ時間 5,214 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from heapq import heapify, heappop, heappush
N, K = map(int, input().split())
A = list(map(int, input().split()))
hp = []
heapify(hp)
s = 0
ans = 0

for i in range(N - 1, -1, -1):
    if (N - 1 - i) < K -1:
        heappush(hp, A[i])
        s += A[i]
    else:
        if i & 1:
            while len(hp) != K - 1:
                a = heappop(hp)
                s -= a
            ans = max(ans, s + A[i])
        heappush(hp, A[i])
        s += A[i] 
print(ans)
0