#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
#define f0(i,n) for(int32_t i = 0; i < (n); i++)
#define f1(i,n) for(int32_t i = 1; i <= (n); i++)
#define inp(n) lli n; cin >> n
#define inparr(arr,n) lli arr[n]; f0(t_ind, n) cin >> arr[t_ind]
#define all(x) (x).begin(), (x).end()
int main () {
inp(n);
inparr(a, n+1);
inparr(b, n);
vector<pair<lli, lli>> arr, brr;
f0(i, n+1) arr.push_back({a[i], i});
f0(i, n) brr.push_back({b[i], i});
sort(all(arr));
sort(all(brr));
lli prefmx[n], sufmx[n];
prefmx[0] = max(arr[0].first-brr[0].first, 0ll);
sufmx[n-1] = max(arr[n].first-brr[n-1].first, 0ll);
for (int32_t i = 1; i < n; i++) {
// prefmx[i] = max(prefmx[i-1], a[i]-b[i]);
prefmx[i] = max(prefmx[i-1], arr[i].first-brr[i].first);
}
for (int32_t i = n-2; i >= 0; i--) {
// sufmx[i] = max(sufmx[i+1], a[i+1]-b[i]);
sufmx[i] = max(sufmx[i+1], arr[i+1].first-brr[i].first);
}
vector<lli> ans;
// cout << sufmx[0] << " ";
ans.push_back(sufmx[0]);
f1(i, n-1) {
// cout << max(prefmx[i-1], sufmx[i]) << " ";
ans.push_back(max(prefmx[i-1], sufmx[i]));
}
// cout << prefmx[n-1] << endl;
ans.push_back(prefmx[n-1]);
lli ans2[n+1];
f0(i, n+1) ans2[arr[i].second] = ans[i];
f0(i, n+1) cout << ans2[i] << " ";
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
436 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
436 KB |
Output is correct |
25 |
Correct |
3 ms |
436 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
464 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
436 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
436 KB |
Output is correct |
25 |
Correct |
3 ms |
436 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
464 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
188 ms |
22444 KB |
Output is correct |
34 |
Correct |
198 ms |
23272 KB |
Output is correct |
35 |
Correct |
197 ms |
22580 KB |
Output is correct |
36 |
Correct |
195 ms |
23124 KB |
Output is correct |
37 |
Correct |
201 ms |
23852 KB |
Output is correct |
38 |
Correct |
198 ms |
23456 KB |
Output is correct |
39 |
Correct |
192 ms |
22380 KB |
Output is correct |
40 |
Correct |
196 ms |
22448 KB |
Output is correct |
41 |
Correct |
192 ms |
22624 KB |
Output is correct |
42 |
Correct |
193 ms |
22484 KB |
Output is correct |
43 |
Correct |
196 ms |
22292 KB |
Output is correct |
44 |
Correct |
188 ms |
21808 KB |
Output is correct |
45 |
Correct |
193 ms |
21956 KB |
Output is correct |
46 |
Correct |
189 ms |
21824 KB |
Output is correct |
47 |
Correct |
207 ms |
22396 KB |
Output is correct |
48 |
Correct |
204 ms |
22556 KB |
Output is correct |
49 |
Correct |
202 ms |
23024 KB |
Output is correct |
50 |
Correct |
199 ms |
22960 KB |
Output is correct |
51 |
Correct |
200 ms |
23032 KB |
Output is correct |
52 |
Correct |
206 ms |
23032 KB |
Output is correct |
53 |
Correct |
206 ms |
22960 KB |
Output is correct |