#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define db double
using namespace std;
ll n;
pair<ll,ll> a[200003];
ll b[200003];
ll mxpref[200003],mxsuf[200003];
int main(){
cin>>n;
for(ll k=1;k<=n+1;k++){
cin>>a[k].ff;
a[k].ss=k;
}
for(ll k=1;k<=n;k++){
cin>>b[k];
}
sort(a+1,a+n+2);
sort(b+1,b+n+1);
ll mx=0,cur;
for(ll k=1;k<=n;k++){
cur=max(0LL,a[k].ff-b[k]);
mx=max(mx,cur);
mxpref[k]=mx;
}
mx=0;
for(ll k=n;k>=1;k--){
cur=max(0LL,a[k+1].ff-b[k]);
mx=max(mx,cur);
mxsuf[k]=mx;
}
ll mx1=0,mx2=0;
ll ans[n+2];
for(ll k=1;k<=n+1;k++){
mx1=mxpref[k-1];
mx2=mxsuf[k];
ans[a[k].ss]=max(mx1,mx2);
}
for(int k=1;k<=n+1;k++)
cout<<ans[k]<<' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
3 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
284 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
3 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
284 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
219 ms |
10676 KB |
Output is correct |
34 |
Correct |
212 ms |
11212 KB |
Output is correct |
35 |
Correct |
201 ms |
10840 KB |
Output is correct |
36 |
Correct |
221 ms |
11296 KB |
Output is correct |
37 |
Correct |
218 ms |
11700 KB |
Output is correct |
38 |
Correct |
204 ms |
11464 KB |
Output is correct |
39 |
Correct |
237 ms |
10516 KB |
Output is correct |
40 |
Correct |
245 ms |
10428 KB |
Output is correct |
41 |
Correct |
239 ms |
10628 KB |
Output is correct |
42 |
Correct |
211 ms |
10580 KB |
Output is correct |
43 |
Correct |
203 ms |
10468 KB |
Output is correct |
44 |
Correct |
209 ms |
10020 KB |
Output is correct |
45 |
Correct |
195 ms |
10280 KB |
Output is correct |
46 |
Correct |
194 ms |
10152 KB |
Output is correct |
47 |
Correct |
207 ms |
10196 KB |
Output is correct |
48 |
Correct |
204 ms |
10120 KB |
Output is correct |
49 |
Correct |
228 ms |
10780 KB |
Output is correct |
50 |
Correct |
253 ms |
10836 KB |
Output is correct |
51 |
Correct |
242 ms |
10836 KB |
Output is correct |
52 |
Correct |
231 ms |
10760 KB |
Output is correct |
53 |
Correct |
251 ms |
10736 KB |
Output is correct |