#include <bits/stdc++.h>
using namespace std;
int main (){
int n;cin>>n;
vector<int> bb(n);
vector<pair<int,int>> arr(n+1);
for(int i = 0;i<=n;i++){
cin>>arr[i].first;
arr[i].second = i;
}
for(int i = 0;i<n;i++)cin>>bb[i];
sort(arr.begin(),arr.end());
sort(bb.begin(),bb.end());
int per[n] , suf[n];
for(int i = 0;i<n;i++){
per[i] = max(arr[i].first-bb[i],0);
if(i)per[i] = max(per[i],per[i-1]);
}
for(int i = n-1;i>=0;i--){
suf[i] = max(arr[i+1].first-bb[i],0);
if(i<n-1)suf[i] = max(suf[i],suf[i+1]);
}
int ans[n+1]={0};
for(int i = 0;i<=n;i++){
if(i==0){
ans[arr[i].second] = suf[i];
}else if(i==n){
ans[arr[i].second] = per[i-1];
}else{
ans[arr[i].second] = max(per[i-1],suf[i]);
}
}
for(int i = 0;i<=n;i++)cout<<ans[i]<<" ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
300 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 |
340 KB |
Output is correct |
15 |
Correct |
2 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 |
340 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 |
312 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
316 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 |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
300 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 |
340 KB |
Output is correct |
15 |
Correct |
2 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 |
340 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 |
312 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
316 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 |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
189 ms |
9928 KB |
Output is correct |
34 |
Correct |
197 ms |
10288 KB |
Output is correct |
35 |
Correct |
187 ms |
9960 KB |
Output is correct |
36 |
Correct |
188 ms |
10572 KB |
Output is correct |
37 |
Correct |
198 ms |
10800 KB |
Output is correct |
38 |
Correct |
201 ms |
10576 KB |
Output is correct |
39 |
Correct |
189 ms |
9804 KB |
Output is correct |
40 |
Correct |
184 ms |
9720 KB |
Output is correct |
41 |
Correct |
194 ms |
9804 KB |
Output is correct |
42 |
Correct |
185 ms |
9808 KB |
Output is correct |
43 |
Correct |
196 ms |
9644 KB |
Output is correct |
44 |
Correct |
182 ms |
9292 KB |
Output is correct |
45 |
Correct |
186 ms |
9320 KB |
Output is correct |
46 |
Correct |
178 ms |
9292 KB |
Output is correct |
47 |
Correct |
186 ms |
9408 KB |
Output is correct |
48 |
Correct |
188 ms |
9412 KB |
Output is correct |
49 |
Correct |
193 ms |
9996 KB |
Output is correct |
50 |
Correct |
192 ms |
9932 KB |
Output is correct |
51 |
Correct |
191 ms |
9928 KB |
Output is correct |
52 |
Correct |
191 ms |
9920 KB |
Output is correct |
53 |
Correct |
193 ms |
9908 KB |
Output is correct |