結果
| 問題 |
No.3050 Prefix Removal
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-03-08 02:11:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 660 bytes |
| コンパイル時間 | 435 ms |
| コンパイル使用メモリ | 82,452 KB |
| 実行使用メモリ | 207,812 KB |
| 最終ジャッジ日時 | 2025-03-08 02:12:03 |
| 合計ジャッジ時間 | 46,792 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 44 |
ソースコード
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:
heappop(Q)
x,y=SX.pop()
heappush(Q,(-y,x))
score+=x
ANS=max(ANS,score)
print(ANS)
titia