#include <iostream>
#include <algorithm>
using namespace std;
int n;
pair<int, int> arr[200005];
int brr[200005];
int suffix[200005];
int prefix[200005];
int answer[200005];
int main(){
cin >> n;
for(int i = 1;i<=n+1;i++){
cin >> arr[i].first;
arr[i].second = i;
}
for(int i = 1;i<=n;i++){
cin >> brr[i];
}
sort(arr+1, arr+n+2);
sort(brr+1, brr+n+1);
int maxi =0;
for(int i = 1; i <= n;i++){
maxi = max(maxi, arr[i].first-brr[i]);
prefix[i] = maxi;
}
maxi = 0;
for(int i = n; i >=1;i--){
maxi = max(maxi, arr[i+1].first-brr[i]);
suffix[i] = maxi;
}
for(int i =1 ; i <=n+1;i++){
answer[arr[i].second] = max(prefix[i-1], suffix[i]);
}
for(int i = 1; i<=n+1;i++){
cout << answer[i] << " ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
440 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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
440 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 |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
496 KB |
Output is correct |
20 |
Correct |
4 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 |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
512 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 |
600 KB |
Output is correct |
32 |
Correct |
4 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
440 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 |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
496 KB |
Output is correct |
20 |
Correct |
4 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 |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
512 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 |
600 KB |
Output is correct |
32 |
Correct |
4 ms |
604 KB |
Output is correct |
33 |
Correct |
129 ms |
9916 KB |
Output is correct |
34 |
Correct |
128 ms |
10320 KB |
Output is correct |
35 |
Correct |
123 ms |
10072 KB |
Output is correct |
36 |
Correct |
127 ms |
10536 KB |
Output is correct |
37 |
Correct |
133 ms |
10916 KB |
Output is correct |
38 |
Correct |
139 ms |
10836 KB |
Output is correct |
39 |
Correct |
130 ms |
9712 KB |
Output is correct |
40 |
Correct |
146 ms |
9728 KB |
Output is correct |
41 |
Correct |
124 ms |
9848 KB |
Output is correct |
42 |
Correct |
124 ms |
9876 KB |
Output is correct |
43 |
Correct |
124 ms |
9884 KB |
Output is correct |
44 |
Correct |
129 ms |
9300 KB |
Output is correct |
45 |
Correct |
161 ms |
9556 KB |
Output is correct |
46 |
Correct |
130 ms |
9244 KB |
Output is correct |
47 |
Correct |
133 ms |
9496 KB |
Output is correct |
48 |
Correct |
153 ms |
9468 KB |
Output is correct |
49 |
Correct |
127 ms |
10056 KB |
Output is correct |
50 |
Correct |
128 ms |
10068 KB |
Output is correct |
51 |
Correct |
139 ms |
10068 KB |
Output is correct |
52 |
Correct |
164 ms |
9964 KB |
Output is correct |
53 |
Correct |
155 ms |
10068 KB |
Output is correct |