이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import sys
input=sys.stdin.readline
n,q=list(map(int,input().split()))
x=list(map(int,input().split()))
y=[]
for i in range(n-1):
y.append([x[i+1]-x[i],i])
wc=0
wm=0
ws=0
y.sort(reverse=True)
L=[0 for i in range(n)]
R=[0 for i in range(n)]
for i in range(q):
z=int(input())
wc+=z
wm=max(wc,wm)
ws=min(wc,ws)
L[0]=-ws
R[n-1]=wm
while len(y) and wm-ws>=y[-1][0]:
c,i=y.pop()
if z<0:
L[i+1]=min(-ws,c-wm)
R[i]=wm
else:
R[i]=min(wm,c+ws)
L[i+1]=-ws
for c,i in y:
L[i+1]=-ws
R[i]=wm
for i in range(n):
print(R[i]+L[i])
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |