#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3F3F3F3F
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int a[n + 2], b[n + 1], p[n + 2], s[n + 3], ans[n + 2];
for (int i = 1; i <= n + 1; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
vector<int> o(n + 2, 0);
iota(o.begin() + 1, o.end(), 1);
sort(o.begin() + 1, o.end(), [&](const int &x, const int &y)
{
return a[x] < a[y];
});
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
p[0] = -inf;
s[n + 2] = -inf;
for (int i = 1; i <= n; i++) p[i] = max(p[i - 1], a[i] - b[i]);
for (int i = n + 1; i > 1; i--) s[i] = max(s[i + 1], a[i] - b[i - 1]);
for (int i = 1; i <= n + 1; i++)
{
ans[o[i]] = max({0LL, p[i - 1], s[i + 1]});
}
for (int i = 1; i <= n + 1; i++) cout << ans[i] << ' ';
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
352 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
352 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
87 ms |
14540 KB |
Output is correct |
34 |
Correct |
98 ms |
15392 KB |
Output is correct |
35 |
Correct |
86 ms |
14484 KB |
Output is correct |
36 |
Correct |
102 ms |
15040 KB |
Output is correct |
37 |
Correct |
90 ms |
15440 KB |
Output is correct |
38 |
Correct |
87 ms |
15440 KB |
Output is correct |
39 |
Correct |
87 ms |
14420 KB |
Output is correct |
40 |
Correct |
86 ms |
14400 KB |
Output is correct |
41 |
Correct |
91 ms |
14676 KB |
Output is correct |
42 |
Correct |
88 ms |
14416 KB |
Output is correct |
43 |
Correct |
86 ms |
14420 KB |
Output is correct |
44 |
Correct |
87 ms |
13892 KB |
Output is correct |
45 |
Correct |
86 ms |
13904 KB |
Output is correct |
46 |
Correct |
86 ms |
13908 KB |
Output is correct |
47 |
Correct |
65 ms |
14264 KB |
Output is correct |
48 |
Correct |
68 ms |
14252 KB |
Output is correct |
49 |
Correct |
89 ms |
14700 KB |
Output is correct |
50 |
Correct |
89 ms |
14788 KB |
Output is correct |
51 |
Correct |
89 ms |
14724 KB |
Output is correct |
52 |
Correct |
90 ms |
14752 KB |
Output is correct |
53 |
Correct |
87 ms |
14712 KB |
Output is correct |