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 |
1 |
Correct |
32 ms |
4952 KB |
Output is correct |
2 |
Correct |
30 ms |
4952 KB |
Output is correct |
3 |
Correct |
31 ms |
4824 KB |
Output is correct |
4 |
Correct |
28 ms |
4952 KB |
Output is correct |
5 |
Correct |
31 ms |
4960 KB |
Output is correct |
6 |
Correct |
28 ms |
4952 KB |
Output is correct |
7 |
Correct |
29 ms |
4960 KB |
Output is correct |
8 |
Correct |
26 ms |
4960 KB |
Output is correct |
9 |
Correct |
31 ms |
4960 KB |
Output is correct |
10 |
Correct |
30 ms |
4960 KB |
Output is correct |
11 |
Correct |
26 ms |
4960 KB |
Output is correct |
12 |
Correct |
26 ms |
4960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
4952 KB |
Output is correct |
2 |
Correct |
30 ms |
4952 KB |
Output is correct |
3 |
Correct |
31 ms |
4824 KB |
Output is correct |
4 |
Correct |
28 ms |
4952 KB |
Output is correct |
5 |
Correct |
31 ms |
4960 KB |
Output is correct |
6 |
Correct |
28 ms |
4952 KB |
Output is correct |
7 |
Correct |
29 ms |
4960 KB |
Output is correct |
8 |
Correct |
26 ms |
4960 KB |
Output is correct |
9 |
Correct |
31 ms |
4960 KB |
Output is correct |
10 |
Correct |
30 ms |
4960 KB |
Output is correct |
11 |
Correct |
26 ms |
4960 KB |
Output is correct |
12 |
Correct |
26 ms |
4960 KB |
Output is correct |
13 |
Correct |
32 ms |
4960 KB |
Output is correct |
14 |
Correct |
35 ms |
5336 KB |
Output is correct |
15 |
Correct |
43 ms |
6360 KB |
Output is correct |
16 |
Correct |
29 ms |
5216 KB |
Output is correct |
17 |
Correct |
50 ms |
6616 KB |
Output is correct |
18 |
Correct |
46 ms |
6104 KB |
Output is correct |
19 |
Correct |
47 ms |
6360 KB |
Output is correct |
20 |
Correct |
53 ms |
7896 KB |
Output is correct |
21 |
Correct |
44 ms |
6360 KB |
Output is correct |
22 |
Correct |
58 ms |
7896 KB |
Output is correct |
23 |
Correct |
48 ms |
6076 KB |
Output is correct |
24 |
Correct |
45 ms |
6232 KB |
Output is correct |
25 |
Correct |
55 ms |
8536 KB |
Output is correct |
26 |
Correct |
46 ms |
6360 KB |
Output is correct |
27 |
Correct |
44 ms |
6488 KB |
Output is correct |
28 |
Correct |
47 ms |
6360 KB |
Output is correct |
29 |
Correct |
45 ms |
6232 KB |
Output is correct |
30 |
Correct |
47 ms |
6360 KB |
Output is correct |
31 |
Correct |
44 ms |
6368 KB |
Output is correct |
32 |
Correct |
50 ms |
6360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
4952 KB |
Output is correct |
2 |
Correct |
30 ms |
4952 KB |
Output is correct |
3 |
Correct |
31 ms |
4824 KB |
Output is correct |
4 |
Correct |
28 ms |
4952 KB |
Output is correct |
5 |
Correct |
31 ms |
4960 KB |
Output is correct |
6 |
Correct |
28 ms |
4952 KB |
Output is correct |
7 |
Correct |
29 ms |
4960 KB |
Output is correct |
8 |
Correct |
26 ms |
4960 KB |
Output is correct |
9 |
Correct |
31 ms |
4960 KB |
Output is correct |
10 |
Correct |
30 ms |
4960 KB |
Output is correct |
11 |
Correct |
26 ms |
4960 KB |
Output is correct |
12 |
Correct |
26 ms |
4960 KB |
Output is correct |
13 |
Correct |
32 ms |
4960 KB |
Output is correct |
14 |
Correct |
35 ms |
5336 KB |
Output is correct |
15 |
Correct |
43 ms |
6360 KB |
Output is correct |
16 |
Correct |
29 ms |
5216 KB |
Output is correct |
17 |
Correct |
50 ms |
6616 KB |
Output is correct |
18 |
Correct |
46 ms |
6104 KB |
Output is correct |
19 |
Correct |
47 ms |
6360 KB |
Output is correct |
20 |
Correct |
53 ms |
7896 KB |
Output is correct |
21 |
Correct |
44 ms |
6360 KB |
Output is correct |
22 |
Correct |
58 ms |
7896 KB |
Output is correct |
23 |
Correct |
48 ms |
6076 KB |
Output is correct |
24 |
Correct |
45 ms |
6232 KB |
Output is correct |
25 |
Correct |
55 ms |
8536 KB |
Output is correct |
26 |
Correct |
46 ms |
6360 KB |
Output is correct |
27 |
Correct |
44 ms |
6488 KB |
Output is correct |
28 |
Correct |
47 ms |
6360 KB |
Output is correct |
29 |
Correct |
45 ms |
6232 KB |
Output is correct |
30 |
Correct |
47 ms |
6360 KB |
Output is correct |
31 |
Correct |
44 ms |
6368 KB |
Output is correct |
32 |
Correct |
50 ms |
6360 KB |
Output is correct |
33 |
Correct |
918 ms |
47180 KB |
Output is correct |
34 |
Correct |
986 ms |
48648 KB |
Output is correct |
35 |
Correct |
965 ms |
48068 KB |
Output is correct |
36 |
Correct |
965 ms |
49820 KB |
Output is correct |
37 |
Correct |
970 ms |
50324 KB |
Output is correct |
38 |
Correct |
956 ms |
54896 KB |
Output is correct |
39 |
Correct |
916 ms |
54640 KB |
Output is correct |
40 |
Correct |
961 ms |
54136 KB |
Output is correct |
41 |
Correct |
975 ms |
54360 KB |
Output is correct |
42 |
Correct |
966 ms |
52504 KB |
Output is correct |
43 |
Correct |
921 ms |
53880 KB |
Output is correct |
44 |
Correct |
937 ms |
57376 KB |
Output is correct |
45 |
Correct |
918 ms |
45836 KB |
Output is correct |
46 |
Correct |
923 ms |
57004 KB |
Output is correct |
47 |
Correct |
741 ms |
52244 KB |
Output is correct |
48 |
Correct |
675 ms |
53524 KB |
Output is correct |
49 |
Correct |
994 ms |
53408 KB |
Output is correct |
50 |
Correct |
994 ms |
53184 KB |
Output is correct |
51 |
Correct |
966 ms |
53176 KB |
Output is correct |
52 |
Correct |
958 ms |
52924 KB |
Output is correct |
53 |
Correct |
993 ms |
52868 KB |
Output is correct |