from bisect import *
n,q = map(int, input().split())
lis = list(map(int, input().split()))
diffs = []
for i in range(n-1):
diffs.append(abs(lis[i] - lis[i+1]))
ans = [0 for i in range(n)]
queries = []
for i in range(q):
queries.append(int(input()))
states = [[0,0,0]]
cur = [0,0,0]
pos = 0
for i in range(q):
pos += queries[i]
sus = False
if pos<0 and cur[1]<abs(pos):
sus = True
cur[1] = abs(pos)
elif pos>0 and cur[2] < pos:
sus = True
cur[2] = pos
if sus:
cur[0] = cur[1] + cur[2]
states.append(list(cur))
for i in range(n-1):
sus = bisect(states, [diffs[i]])
if sus==1:
ans[i+1] += states[1][1]
ans[i] += states[1][2]
elif sus==len(states):
ans[i+1] += states[-1][1]
ans[i] += states[-1][2]
else:
if states[sus-1][1] == states[sus][1]:
ans[i+1] += states[sus][1]
ans[i] += diffs[i] - states[sus][1]
else:
ans[i] += states[sus][2]
ans[i+1] += diffs[i] - states[sus][2]
ans[0] += states[-1][1]
ans[-1] += states[-1][2]
for i in ans:
print(i)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
22564 KB |
Output is correct |
2 |
Correct |
89 ms |
22396 KB |
Output is correct |
3 |
Correct |
92 ms |
22764 KB |
Output is correct |
4 |
Correct |
131 ms |
26116 KB |
Output is correct |
5 |
Correct |
137 ms |
26616 KB |
Output is correct |
6 |
Correct |
135 ms |
26544 KB |
Output is correct |
7 |
Correct |
132 ms |
26544 KB |
Output is correct |
8 |
Correct |
133 ms |
26408 KB |
Output is correct |
9 |
Correct |
127 ms |
26292 KB |
Output is correct |
10 |
Correct |
147 ms |
26272 KB |
Output is correct |
11 |
Correct |
117 ms |
25096 KB |
Output is correct |
12 |
Correct |
36 ms |
18176 KB |
Output is correct |
13 |
Correct |
37 ms |
18228 KB |
Output is correct |
14 |
Incorrect |
46 ms |
18972 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
22564 KB |
Output is correct |
2 |
Correct |
89 ms |
22396 KB |
Output is correct |
3 |
Correct |
92 ms |
22764 KB |
Output is correct |
4 |
Correct |
131 ms |
26116 KB |
Output is correct |
5 |
Correct |
137 ms |
26616 KB |
Output is correct |
6 |
Correct |
135 ms |
26544 KB |
Output is correct |
7 |
Correct |
132 ms |
26544 KB |
Output is correct |
8 |
Correct |
133 ms |
26408 KB |
Output is correct |
9 |
Correct |
127 ms |
26292 KB |
Output is correct |
10 |
Correct |
147 ms |
26272 KB |
Output is correct |
11 |
Correct |
117 ms |
25096 KB |
Output is correct |
12 |
Correct |
36 ms |
18176 KB |
Output is correct |
13 |
Correct |
37 ms |
18228 KB |
Output is correct |
14 |
Incorrect |
46 ms |
18972 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |