結果

問題 No.2028 Even Choice
ユーザー ああいい
提出日時 2022-08-07 16:36:00
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 435 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 104,104 KB
最終ジャッジ日時 2024-09-17 09:49:59
合計ジャッジ時間 6,029 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 RE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K = map(int,input().split())
A = list(map(int,input().split()))
import heapq
now = A[N - K + 1:N]
heapq.heapify(now)
ans = 0
nsum = sum(now)
#print(nsum)

i = N - K
for j in range(i,-1,-1):
    if j & 1:
        tmp = nsum + A[j]
        if tmp > ans:
            ans = tmp
    t = heapq.heappop(now)
    if A[j] > t:
        heapq.heappush(now,A[j])
        nsum = nsum - t + A[j]
    else:
        heapq.heappush(now,t)
print(ans)
0