#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<long long, long long>
#define fr first
#define se second
int32_t main() {
//freopen("in", "r", stdin);
int n;
cin >> n;
vector<pii> a(n + 2);
vector<int> b(n + 1);
for (int i = 1; i <= (n + 1); i++) {
cin >> a[i].fr;
a[i].se = i;
}
for (int i = 1; i <= n; i++) cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> pf(n + 5), sf(n + 5);
for (int i = 1; i <= n; i++) {
int c = max(a[i].fr - b[i], 0LL);
pf[i] = max(pf[i - 1], c);
}
for (int i = n + 1; i >= 2; i--) {
int c = max(a[i].fr - b[i - 1], 0LL);
sf[i] = max(sf[i + 1], c);
}
vector<int> ans(n + 2);
for (int i = 1; i <= (n + 1); i++) {
ans[a[i].se] = max(pf[i - 1], sf[i + 1]);
}
for (int i = 1; i <= (n + 1); i++) cout << ans[i] << " ";
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
344 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 |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 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 |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
344 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 |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 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 |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
145 ms |
14420 KB |
Output is correct |
34 |
Correct |
141 ms |
15076 KB |
Output is correct |
35 |
Correct |
137 ms |
14528 KB |
Output is correct |
36 |
Correct |
150 ms |
14944 KB |
Output is correct |
37 |
Correct |
141 ms |
15604 KB |
Output is correct |
38 |
Correct |
142 ms |
15420 KB |
Output is correct |
39 |
Correct |
148 ms |
14332 KB |
Output is correct |
40 |
Correct |
139 ms |
14420 KB |
Output is correct |
41 |
Correct |
139 ms |
14416 KB |
Output is correct |
42 |
Correct |
138 ms |
14416 KB |
Output is correct |
43 |
Correct |
144 ms |
14416 KB |
Output is correct |
44 |
Correct |
134 ms |
13724 KB |
Output is correct |
45 |
Correct |
139 ms |
13904 KB |
Output is correct |
46 |
Correct |
135 ms |
13904 KB |
Output is correct |
47 |
Correct |
139 ms |
14168 KB |
Output is correct |
48 |
Correct |
137 ms |
14164 KB |
Output is correct |
49 |
Correct |
149 ms |
14672 KB |
Output is correct |
50 |
Correct |
141 ms |
14672 KB |
Output is correct |
51 |
Correct |
142 ms |
14676 KB |
Output is correct |
52 |
Correct |
140 ms |
14672 KB |
Output is correct |
53 |
Correct |
148 ms |
14724 KB |
Output is correct |