from sys import stdin
input = stdin.readline
gi = lambda: list(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 range(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 range(n - 2, -1, -1):
suf[i] = max(suf[i + 1], max(arr[i + 1] - brr[i], 0))
ans = []
for _, i in queries:
if i == 0:
ans.append(suf[0])
elif i == n:
ans.append(pre[-1])
else:
ans.append(max(pre[i - 1], suf[i]))
print(" ".join(map(str, ans)))
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
3344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
3344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
3344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |