結果

問題 No.2028 Even Choice
ユーザー wattaiheiwattaihei
提出日時 2022-08-05 22:38:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 362 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 112,952 KB
最終ジャッジ日時 2024-09-15 19:58:12
合計ジャッジ時間 5,305 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from heapq import heappop, heappush

N, K = map(int, input().rstrip().split())
A = list(map(int, input().rstrip().split()))

q = []
qs = 0
ans = 0
for i in reversed(range(N)):
    a = A[i]
    if i%2 == 1:
        ans = max(ans, qs + a)
    heappush(q, a)
    qs += a
    if len(q) >= K:
        qs -= heappop(q)

print(ans)
0