結果

問題 No.2028 Even Choice
コンテスト
ユーザー asumo0729
提出日時 2022-08-06 15:52:52
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 146 ms / 2,000 ms
+ 683µs
コード長 382 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 285 ms
コンパイル使用メモリ 64,404 KB
実行使用メモリ 89,368 KB
最終ジャッジ日時 2026-10-16 15:56:18
合計ジャッジ時間 5,698 ms
ジャッジサーバーID
(参考情報)
judge5_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 = [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