/*
* author : Apiram
* created: 29.06.2023 02:12:41
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
vector<pair<int,int>>arr(n + 1);
for (int i = 0;i<=n;++i){
cin>>arr[i].first;
arr[i].second = i;
}
sort(arr.begin(),arr.end());
vector<int>brr(n);
for (int i = 0;i<n;++i){
cin>>brr[i];
}
sort(brr.begin(),brr.end());
vector<int>pref(n,0),suff(n + 1,0);
for (int i = 0;i<n;++i){
pref[i] = max(0,arr[i].first - brr[i]);
if (i){
pref[i]=max(pref[i - 1],pref[i]);
}
// cout<<pref[i]<<" ";
}
//cout<<'\n';
for (int i = n;i > 0;--i){
suff[i] = max(0,arr[i].first - brr[i - 1]);
if (i != n){
suff[i] = max(suff[i],suff[i + 1]);
}
//cout<<suff[i]<<" ";
}
vector<int>ans(n + 1);
for (int i = 0;i<=n;++i){
ans[arr[i].second] = 0;
if (i - 1>=0){
ans[arr[i].second]=max(ans[arr[i].second],pref[i - 1]);
}
if (i + 1 <= n){
ans[arr[i].second]=max(ans[arr[i].second],suff[i + 1]);
}
}
for (auto x:ans){
cout<<x<<" ";
}
cout<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
67 ms |
9956 KB |
Output is correct |
34 |
Correct |
71 ms |
10308 KB |
Output is correct |
35 |
Correct |
69 ms |
10048 KB |
Output is correct |
36 |
Correct |
69 ms |
10524 KB |
Output is correct |
37 |
Correct |
72 ms |
10836 KB |
Output is correct |
38 |
Correct |
72 ms |
10672 KB |
Output is correct |
39 |
Correct |
69 ms |
9676 KB |
Output is correct |
40 |
Correct |
69 ms |
9664 KB |
Output is correct |
41 |
Correct |
70 ms |
9804 KB |
Output is correct |
42 |
Correct |
69 ms |
9796 KB |
Output is correct |
43 |
Correct |
68 ms |
9820 KB |
Output is correct |
44 |
Correct |
68 ms |
9336 KB |
Output is correct |
45 |
Correct |
70 ms |
9352 KB |
Output is correct |
46 |
Correct |
68 ms |
9348 KB |
Output is correct |
47 |
Correct |
65 ms |
9420 KB |
Output is correct |
48 |
Correct |
65 ms |
9428 KB |
Output is correct |
49 |
Correct |
71 ms |
9952 KB |
Output is correct |
50 |
Correct |
72 ms |
10056 KB |
Output is correct |
51 |
Correct |
70 ms |
9996 KB |
Output is correct |
52 |
Correct |
76 ms |
10072 KB |
Output is correct |
53 |
Correct |
71 ms |
9996 KB |
Output is correct |