結果

問題 No.3050 Prefix Removal
ユーザー rin204
提出日時 2025-02-02 14:47:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 350 bytes
コンパイル時間 1,085 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 202,692 KB
最終ジャッジ日時 2025-03-07 20:32:16
合計ジャッジ時間 17,887 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 54 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, K = map(int, input().split())
A = list(map(int, input().split()))
tot = 0
l_tot = 0
hq = []

ans = -(1 << 60)
for a in A:
    tot += a

    if len(hq) >= K - 1:
        score = tot * K - l_tot
        ans = max(ans, score)

    l_tot += tot
    heappush(hq, -tot)
    if len(hq) == K:
        l_tot += heappop(hq)

print(ans)
0