結果

問題 No.2028 Even Choice
ユーザー Eguy
提出日時 2022-08-05 21:40:49
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 740 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 113,800 KB
最終ジャッジ日時 2024-09-15 18:00:33
合計ジャッジ時間 5,467 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 RE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, math
sys.setrecursionlimit(1000000)
INF = 1 << 100
#mod = 1000000007
mod = 998244353
input = lambda: sys.stdin.readline().rstrip()
li = lambda: list(map(int, input().split()))
from heapq import *

N, K = li()
A = li()

if K == 1:
    ans = -INF
    for i in range(1, N, 2):
        ans = max(ans, A[i])
    print(ans)

hq = []
su = 0
acc = [-INF] * N
for i in range(N)[::-1]:
    a = A[i]
    if len(hq) == K-1:
        x = heappop(hq)
        if x > a:
            heappush(hq, x)
        else:
            heappush(hq, a)
            su += a - x
    else:
        su += a
        heappush(hq, a)
    if len(hq) == K-1:
        acc[i] = su

ans = -INF
for i in range(1, N-1, 2):
    ans = max(ans, A[i] + acc[i+1])

print(ans)
0