結果

問題 No.3050 Prefix Removal
ユーザー 👑 rin204
提出日時 2025-02-02 14:49:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 454 ms / 2,000 ms
コード長 391 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 82,296 KB
実行使用メモリ 206,084 KB
最終ジャッジ日時 2025-03-07 20:32:36
合計ジャッジ時間 17,750 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

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

ans = 0
for i, a in enumerate(A[:K], 1):
    ans += i * a
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