結果

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

ソースコード

diff #

import heapq
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
hq = []
for i in range(n - k + 1, n):
    ans += a[i]
    heapq.heappush(hq, a[i])
res = 0
for i in range(n - k, -1, -1):
    if i % 2:
        if res < ans + a[i]:
            res = ans + a[i]
    ans += a[i]
    heapq.heappush(hq, a[i])
    ans -= heapq.heappop(hq)
print(res)
0