#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second
void solve(){
int n;
cin>>n;
pll arr[n+1];
for(int i = 0;i<=n;i++){
arr[i].sc = i;
cin>>arr[i].fs;
}
pll brr[n];
for(int i = 0;i<n;i++){
brr[i].sc = i;
cin>>brr[i].fs;
}
sort(arr,arr+n+1);
sort(brr,brr+n);
ll pref[n+1];
ll suf[n+1];
pref[0] = max(0LL,arr[0].fs-brr[0].fs);
ll ans[n+1];
for(int i = 1;i<n;i++){
pref[i] = max(pref[i-1],max(0LL,arr[i].fs-brr[i].fs));
}
suf[n] = max(0LL,arr[n].fs-brr[n-1].fs);
for(int i = n-1;i>=1;i--){
suf[i] = max(suf[i+1],max(0LL,arr[i].fs-brr[i-1].fs));
}
ans[arr[0].sc] = suf[1];
ans[arr[n].sc] = pref[n-1];
for(int i = 1;i<n;i++){
ans[arr[i].sc] = max(pref[i-1],suf[i+1]);
}
for(int i = 0;i<=n;i++)cout<<ans[i]<<' ';cout<<'\n';
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
while(t--)solve();
}
Compilation message
ho_t1.cpp: In function 'void solve()':
ho_t1.cpp:41:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
41 | for(int i = 0;i<=n;i++)cout<<ans[i]<<' ';cout<<'\n';
| ^~~
ho_t1.cpp:41:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
41 | for(int i = 0;i<=n;i++)cout<<ans[i]<<' ';cout<<'\n';
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
212 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 |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
464 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 |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
212 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 |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
464 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 |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
86 ms |
15932 KB |
Output is correct |
34 |
Correct |
116 ms |
16584 KB |
Output is correct |
35 |
Correct |
88 ms |
15944 KB |
Output is correct |
36 |
Correct |
93 ms |
16460 KB |
Output is correct |
37 |
Correct |
91 ms |
17116 KB |
Output is correct |
38 |
Correct |
95 ms |
16832 KB |
Output is correct |
39 |
Correct |
88 ms |
15856 KB |
Output is correct |
40 |
Correct |
94 ms |
15740 KB |
Output is correct |
41 |
Correct |
87 ms |
15900 KB |
Output is correct |
42 |
Correct |
84 ms |
15888 KB |
Output is correct |
43 |
Correct |
94 ms |
15772 KB |
Output is correct |
44 |
Correct |
84 ms |
15312 KB |
Output is correct |
45 |
Correct |
86 ms |
15404 KB |
Output is correct |
46 |
Correct |
91 ms |
15308 KB |
Output is correct |
47 |
Correct |
105 ms |
15716 KB |
Output is correct |
48 |
Correct |
95 ms |
15716 KB |
Output is correct |
49 |
Correct |
90 ms |
16320 KB |
Output is correct |
50 |
Correct |
101 ms |
16280 KB |
Output is correct |
51 |
Correct |
94 ms |
16312 KB |
Output is correct |
52 |
Correct |
88 ms |
16220 KB |
Output is correct |
53 |
Correct |
99 ms |
16284 KB |
Output is correct |