結果

問題 No.2028 Even Choice
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-08-05 22:06:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 528 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 81,984 KB
実行使用メモリ 112,360 KB
最終ジャッジ日時 2024-09-15 18:59:17
合計ジャッジ時間 5,225 ms
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

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