結果

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

ソースコード

diff #

from heapq import heappush, heappop

H = []
hpush = lambda x: heappush(H, x)
hpop = lambda: heappop(H)
hmin = lambda: H[0] if H else 0

N, K = map(int, input().split())
A = [int(a) for a in input().split()]
s = 0
for i in range(N - K + 1, N):
    a = A[i]
    s += a
    hpush(a)

ans = 0
for i in range(N - K + 1)[::-1]:
    a = A[i]
    if i % 2:
        ans = max(ans, s + a)
    
    m = hmin()
    if K > 1 and a > m:
        hpush(a)
        hpop()
        s += a - m
    
print(ans)
0