This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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)
u=[0 for i in range(n)]
for i in range(q):
z=int(input())
wc+=z
wm=max(wc,wm)
ws=min(wc,ws)
while len(y) and wm-ws>=y[-1][0]:
c,i=y.pop()
if z<0:
u[i+1]+=c-wm
u[i]+=wm
else:
u[i]+=c+ws
u[i+1]-=ws
while len(y):
c,i=y.pop()
u[i]+=wm
u[i+1]-=ws
u[0]-=ws
u[n-1]+=wm
for c in u:
print(c)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |