結果
| 問題 |
No.3303 Heal Slimes 2
|
| コンテスト | |
| ユーザー |
sasa8uyauya
|
| 提出日時 | 2025-10-11 12:06:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 660 bytes |
| コンパイル時間 | 287 ms |
| コンパイル使用メモリ | 82,348 KB |
| 実行使用メモリ | 92,600 KB |
| 最終ジャッジ日時 | 2025-10-11 12:06:26 |
| 合計ジャッジ時間 | 6,305 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 31 |
ソースコード
n,K,D=map(int,input().split())
a=list(map(int,input().split()))
ans=sum(a)
from sortedcontainers import SortedList
X=10**10
pl=SortedList([-X])
pr=SortedList([X])
h=0
for i in range(n):
v=a[i]
l,r=v-D,v
if l<=pr[0]:
pl.add(l)
else:
h+=l-pr[0]
pl.add(pr.pop(0))
pr.add(l)
if pl[-1]<=r:
pr.add(r)
else:
h+=pl[-1]-r
pr.add(pl.pop(-1))
pl.add(r)
if i<K-1:
continue
ans=min(ans,h)
v=a[i-(K-1)]
l,r=v-D,v
if l<=pl[-1]:
pl.discard(l)
else:
h-=l-pl[-1]
pr.discard(l)
pr.add(pl.pop(-1))
if pr[0]<=r:
pr.discard(r)
else:
h-=pr[0]-r
pl.discard(r)
pl.add(pr.pop(0))
print(ans)
sasa8uyauya