結果
問題 |
No.3050 Prefix Removal
|
ユーザー |
![]() |
提出日時 | 2025-03-08 02:13:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,618 ms / 2,000 ms |
コード長 | 681 bytes |
コンパイル時間 | 457 ms |
コンパイル使用メモリ | 82,496 KB |
実行使用メモリ | 207,324 KB |
最終ジャッジ日時 | 2025-03-08 02:14:27 |
合計ジャッジ時間 | 47,779 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 55 |
ソースコード
import sys input = sys.stdin.readline from heapq import heappop,heappush N,K=map(int,input().split()) A=list(map(int,input().split())) S=[(0,-1)] for i in range(N-1,-1,-1): S.append((S[-1][0]+A[i],i)) score=0 SX=[] for i in range(len(S)): if S[i][1]==0: score+=S[i][0] elif S[i][1]>=1: SX.append(S[i]) SX.sort() Q=[] while len(Q)<K-1: x,y=SX.pop() heappush(Q,(-y,x)) score+=x ANS=score for i in range(N-1,K-1,-1): # iを削除 score-=A[i]*K while Q and -Q[0][0]>=i: _,x=heappop(Q) score-=x x,y=SX.pop() heappush(Q,(-y,x)) score+=x ANS=max(ANS,score) print(ANS)