#include "bits/stdc++.h"
using namespace std;
const int N = 2e5 + 5;
int n, a[N], b[N];
int p[N], o[N], pf[N], sf[N];
int main() {
cin.tie(0)->sync_with_stdio(0), cin.exceptions(cin.failbit);
cin >> n;
for (int i = 0; i <= n; i++) cin >> a[i], p[i] = i;
for (int i = 0; i < n; i++) cin >> b[i];
sort(p, p + n + 1, [ & ](int i, int j) {
return a[i] < a[j];
});
for (int i = 0; i <= n; i++) o[p[i]] = i;
sort(b, b + n);
for (int i = 0; i < n; i++) pf[i] = max(i > 0 ? pf[i - 1] : 0, max(a[p[i]] - b[i], 0));
for (int i = n; i >= 1; i--) sf[i] = max(i < n ? sf[i + 1] : 0, max(a[p[i]] - b[i - 1], 0));
for (int i = 0; i <= n; i++) {
int j = o[i];
cout << max(j > 0 ? pf[j - 1] : 0, j < n ? sf[j + 1] : 0) << " \n" [i == n];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4556 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4604 KB |
Output is correct |
18 |
Correct |
2 ms |
4448 KB |
Output is correct |
19 |
Correct |
1 ms |
4596 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4440 KB |
Output is correct |
27 |
Correct |
1 ms |
4440 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4556 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4604 KB |
Output is correct |
18 |
Correct |
2 ms |
4448 KB |
Output is correct |
19 |
Correct |
1 ms |
4596 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4440 KB |
Output is correct |
27 |
Correct |
1 ms |
4440 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
71 ms |
10296 KB |
Output is correct |
34 |
Correct |
80 ms |
10328 KB |
Output is correct |
35 |
Correct |
82 ms |
10320 KB |
Output is correct |
36 |
Correct |
72 ms |
10580 KB |
Output is correct |
37 |
Correct |
87 ms |
10832 KB |
Output is correct |
38 |
Correct |
87 ms |
10828 KB |
Output is correct |
39 |
Correct |
76 ms |
9984 KB |
Output is correct |
40 |
Correct |
78 ms |
9784 KB |
Output is correct |
41 |
Correct |
81 ms |
10048 KB |
Output is correct |
42 |
Correct |
80 ms |
9820 KB |
Output is correct |
43 |
Correct |
77 ms |
9812 KB |
Output is correct |
44 |
Correct |
81 ms |
9628 KB |
Output is correct |
45 |
Correct |
77 ms |
9660 KB |
Output is correct |
46 |
Correct |
72 ms |
9556 KB |
Output is correct |
47 |
Correct |
59 ms |
9552 KB |
Output is correct |
48 |
Correct |
86 ms |
9560 KB |
Output is correct |
49 |
Correct |
79 ms |
10060 KB |
Output is correct |
50 |
Correct |
77 ms |
10068 KB |
Output is correct |
51 |
Correct |
89 ms |
10064 KB |
Output is correct |
52 |
Correct |
91 ms |
10064 KB |
Output is correct |
53 |
Correct |
78 ms |
9948 KB |
Output is correct |