#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int32_t n;
std::cin >> n;
std::vector< std::pair< int32_t, int32_t > > a(n + 1);
for(int32_t i = 0; i < n + 1; i++) {
std::cin >> a[i].first;
a[i].second = i;
}
std::vector< int32_t > b(n);
for(int32_t i = 0; i < n; i++) {
std::cin >> b[i];
}
std::sort(a.begin(), a.end());
std::sort(b.begin(), b.end());
std::vector< int32_t > prefMax(n), suffMax(n);
for(int32_t i = 0; i < n; i++) {
if(i != 0) {
prefMax[i] = prefMax[i - 1];
}
else {
prefMax[i] = 0;
}
prefMax[i] = std::max(prefMax[i], a[i].first - b[i]);
}
for(int32_t i = n - 1; i >= 0; i--) {
if(i != n - 1) {
suffMax[i] = suffMax[i + 1];
}
else {
suffMax[i] = 0;
}
suffMax[i] = std::max(suffMax[i], a[i + 1].first - b[i]);
}
std::vector< int32_t > ans(n + 1);
ans[a[0].second] = suffMax[0];
for(int32_t i = 1; i <= n - 1; i++) {
ans[a[i].second] = std::max(prefMax[i - 1], suffMax[i]);
}
ans[a[n].second] = prefMax[n - 1];
for(auto &x : ans) {
std::cout << x << " ";
}
std::cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
7 ms |
504 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
380 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
7 ms |
504 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
380 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
6 ms |
376 KB |
Output is correct |
33 |
Correct |
120 ms |
6392 KB |
Output is correct |
34 |
Correct |
113 ms |
6648 KB |
Output is correct |
35 |
Correct |
114 ms |
6392 KB |
Output is correct |
36 |
Correct |
122 ms |
6908 KB |
Output is correct |
37 |
Correct |
123 ms |
7036 KB |
Output is correct |
38 |
Correct |
121 ms |
7032 KB |
Output is correct |
39 |
Correct |
111 ms |
6008 KB |
Output is correct |
40 |
Correct |
114 ms |
6004 KB |
Output is correct |
41 |
Correct |
125 ms |
6136 KB |
Output is correct |
42 |
Correct |
114 ms |
6136 KB |
Output is correct |
43 |
Correct |
125 ms |
6008 KB |
Output is correct |
44 |
Correct |
114 ms |
5756 KB |
Output is correct |
45 |
Correct |
136 ms |
5752 KB |
Output is correct |
46 |
Correct |
118 ms |
5880 KB |
Output is correct |
47 |
Correct |
114 ms |
5624 KB |
Output is correct |
48 |
Correct |
114 ms |
5624 KB |
Output is correct |
49 |
Correct |
118 ms |
6264 KB |
Output is correct |
50 |
Correct |
123 ms |
6264 KB |
Output is correct |
51 |
Correct |
131 ms |
6188 KB |
Output is correct |
52 |
Correct |
123 ms |
6264 KB |
Output is correct |
53 |
Correct |
131 ms |
6232 KB |
Output is correct |