#include "bits/stdc++.h"
using namespace std;
const int N=2e5+5;
int n,a[N],b[N];
int p[N],o[N],pf[N],sf[N];
int main() {
cin.tie(0)->sync_with_stdio(0),cin.exceptions(cin.failbit);
cin>>n;
for(int i=0;i<=n;i++)cin>>a[i],p[i]=i;
for(int i=0;i<n;i++)cin>>b[i];
sort(p,p+n+1,[&](int i,int j){return a[i]<a[j];});
for(int i=0;i<=n;i++)o[p[i]]=i;
sort(b,b+n);
for(int i=0;i<n;i++)pf[i]=max(i>0?pf[i-1]:0,max(a[p[i]]-b[i],0));
for(int i=n;i>=1;i--)sf[i]=max(i<n?sf[i+1]:0,max(a[p[i]]-b[i-1],0));
for(int i=0;i<=n;i++){
int j=o[i];
cout<<max(j>0?pf[j-1]:0,j<n?sf[j+1]:0)<<" \n"[i==n];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4452 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4452 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
2 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
2 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4452 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
2 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
2 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
73 ms |
10080 KB |
Output is correct |
34 |
Correct |
72 ms |
10324 KB |
Output is correct |
35 |
Correct |
71 ms |
10184 KB |
Output is correct |
36 |
Correct |
74 ms |
10720 KB |
Output is correct |
37 |
Correct |
76 ms |
10856 KB |
Output is correct |
38 |
Correct |
73 ms |
10836 KB |
Output is correct |
39 |
Correct |
71 ms |
9812 KB |
Output is correct |
40 |
Correct |
77 ms |
9884 KB |
Output is correct |
41 |
Correct |
74 ms |
10016 KB |
Output is correct |
42 |
Correct |
73 ms |
9812 KB |
Output is correct |
43 |
Correct |
71 ms |
9812 KB |
Output is correct |
44 |
Correct |
69 ms |
9556 KB |
Output is correct |
45 |
Correct |
70 ms |
9656 KB |
Output is correct |
46 |
Correct |
72 ms |
9556 KB |
Output is correct |
47 |
Correct |
56 ms |
9556 KB |
Output is correct |
48 |
Correct |
58 ms |
9556 KB |
Output is correct |
49 |
Correct |
74 ms |
10156 KB |
Output is correct |
50 |
Correct |
73 ms |
10068 KB |
Output is correct |
51 |
Correct |
80 ms |
10188 KB |
Output is correct |
52 |
Correct |
73 ms |
10064 KB |
Output is correct |
53 |
Correct |
74 ms |
10108 KB |
Output is correct |