#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
signed main() {
int n;
cin >> n;
vector<int> b(n);
vector <pair <int, int>> a(n + 1);
for (int i = 0; i <= n; ++i) {
int x;
cin >> x;
a[i] = {x, i};
}
for (auto &u : b) {
cin >> u;
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector <int> preff(n + 1, 0), suff(n + 1, 0);
vector <int> ans(n + 1);
for (int i = 0; i < n; ++i) {
int now = max(a[i].first - b[i], 0ll);
preff[i] = now;
if (i != 0) {
preff[i] = max(preff[i], preff[i - 1]);
}
}
preff[n] = preff[n - 1];
for (int i = n - 1; i >= 0; --i) {
int now = max(a[i + 1].first - b[i], 0ll);
suff[i + 1] = now;
if (i != n - 1) {
suff[i + 1] = max(suff[i + 1], suff[i + 2]);
}
}
suff[0] = suff[1];
for (int i = 0; i <= n; ++i) {
int pos = a[i].second;
int now = 0;
if (i != 0) {
now += preff[i - 1];
}
if (i != n) {
now = max(now, suff[i + 1]);
}
ans[pos] = now;
}
for (auto u : ans) {
cout << u << ' ';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
396 KB |
Output is correct |
17 |
Correct |
3 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
3 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
2 ms |
492 KB |
Output is correct |
30 |
Correct |
3 ms |
492 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
3 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
396 KB |
Output is correct |
17 |
Correct |
3 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
3 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
2 ms |
492 KB |
Output is correct |
30 |
Correct |
3 ms |
492 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
3 ms |
492 KB |
Output is correct |
33 |
Correct |
242 ms |
14572 KB |
Output is correct |
34 |
Correct |
235 ms |
15084 KB |
Output is correct |
35 |
Correct |
224 ms |
14572 KB |
Output is correct |
36 |
Correct |
235 ms |
15148 KB |
Output is correct |
37 |
Correct |
236 ms |
15596 KB |
Output is correct |
38 |
Correct |
237 ms |
15484 KB |
Output is correct |
39 |
Correct |
228 ms |
14316 KB |
Output is correct |
40 |
Correct |
226 ms |
14316 KB |
Output is correct |
41 |
Correct |
227 ms |
14444 KB |
Output is correct |
42 |
Correct |
227 ms |
14444 KB |
Output is correct |
43 |
Correct |
225 ms |
14316 KB |
Output is correct |
44 |
Correct |
218 ms |
13804 KB |
Output is correct |
45 |
Correct |
226 ms |
14060 KB |
Output is correct |
46 |
Correct |
221 ms |
13804 KB |
Output is correct |
47 |
Correct |
224 ms |
14188 KB |
Output is correct |
48 |
Correct |
224 ms |
14284 KB |
Output is correct |
49 |
Correct |
242 ms |
14828 KB |
Output is correct |
50 |
Correct |
237 ms |
14828 KB |
Output is correct |
51 |
Correct |
230 ms |
14828 KB |
Output is correct |
52 |
Correct |
241 ms |
14828 KB |
Output is correct |
53 |
Correct |
235 ms |
14828 KB |
Output is correct |