Submission #245551

# Submission time Handle Problem Language Result Execution time Memory
245551 2020-07-06T17:37:20 Z zecookiez Just Long Neckties (JOI20_ho_t1) PyPy
0 / 100
26 ms 4960 KB
from sys import stdin
input = stdin.readline
gi = lambda: tuple(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()

suf = [1e18] * n
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, (val, ind) in enumerate(queries):
    if i == 0:
        ans[ind] = suf[0]
        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
1 Runtime error 26 ms 4960 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 4960 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 4960 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -