結果

問題 No.2028 Even Choice
コンテスト
ユーザー aaaaaaaaaa2230
提出日時 2022-08-05 22:06:29
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 528 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 174 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 114,048 KB
最終ジャッジ日時 2026-04-04 21:46:05
合計ジャッジ時間 4,348 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from heapq import heappop,heappush

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

ans = 0

score = 0
size = 0
h = []

for i in range(n)[::-1]:
    a = A[i]
    if i%2 == 0:
        size += 1
        heappush(h,a)
        score += a

        continue
    # print(i,a,h,score)
    while size > k:
        x = heappop(h)
        size -= 1
        score -= x
    if size == k:
        ans = max(ans,score+a-h[0])
    else:
        ans = max(ans,score+a)
    heappush(h,a)
    score += a
    size += 1
print(ans)
0