This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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 = sorted(gi())
arr.sort()
suf = [0]
for i, val in enumerate(reversed(brr)):
suf.append(max(suf[-1], max(arr[~i] - val, 0)))
ans = [0] * (n + 1)
for i, (val, ind) in enumerate(queries):
if i == 0:
ans[ind] = suf[-1]
pre = max(val - brr[i], 0)
elif i == n:
ans[ind] = pre
else:
ans[ind] = max(pre, suf[~i])
pre = max(pre, max(val - brr[i], 0))
print " ".join(map(str, ans))
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |