from sys import stdin
input = stdin.readline
gi = lambda: map(int, input().split())
n = int(input())
arr = gi()
queries = sorted((i, j) for j, i in enumerate(arr))
brr = gi()
arr.sort()
brr.sort()
pre = [1e18] * n
suf = [1e18] * n
pre[0] = max(arr[0] - brr[0], 0)
for i in xrange(1, n):
pre[i] = max(pre[i - 1], max(arr[i] - brr[i], 0))
suf[n - 1] = max(arr[-1] - brr[-1], 0)
for i in xrange(n - 2, -1, -1):
suf[i] = max(suf[i + 1], max(arr[i + 1] - brr[i], 0))
ans = [0] * (n + 1)
for _, i in queries:
if i == 0:
ans[i] = suf[0]
elif i == n:
ans[i] = pre[-1]
else:
ans[i] = max(pre[i - 1], suf[i])
print " ".join(map(str, ans))
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
4960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
4960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
4960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |