#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n; cin>>n;
int cnt = 0;
vector<pair<int,int>> v(n+1); for(auto& i : v) cnt++,cin>>i.first, i.second = cnt-1;
vector<int> b(n); for(int& i : b) cin>>i;
sort(b.begin(),b.end());
// cout<<endl;
vector<int> ans(n+1);
sort(v.begin(),v.end());
vector<int> pre(n+1,0), suf(n+1,0);
for(int i = 0; i<n; i++){
pre[i+1] = max(pre[i], v[i].first-b[i]);
}
for(int i = n-1; i>=0; i--){
suf[i] = max(suf[i+1], v[i+1].first - b[i]);
}
// for(int i : pre) cout<<i<<" ";
// cout<<endl;
// for(int i : suf) cout<<i<<" "; cout<<endl;
for(int i = 0; i<=n; i++){
ans[v[i].second] = max(pre[i], suf[i]);
}
for(int i : ans) cout<<i<<" "; cout<<endl;
}
Compilation message
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:28:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
28 | for(int i : ans) cout<<i<<" "; cout<<endl;
| ^~~
ho_t1.cpp:28:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
28 | for(int i : ans) cout<<i<<" "; cout<<endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
500 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
400 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
2 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
448 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
352 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
500 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
400 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
2 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
448 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
352 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
156 ms |
14352 KB |
Output is correct |
34 |
Correct |
155 ms |
14928 KB |
Output is correct |
35 |
Correct |
164 ms |
14512 KB |
Output is correct |
36 |
Correct |
159 ms |
15056 KB |
Output is correct |
37 |
Correct |
157 ms |
15580 KB |
Output is correct |
38 |
Correct |
160 ms |
15252 KB |
Output is correct |
39 |
Correct |
156 ms |
14412 KB |
Output is correct |
40 |
Correct |
152 ms |
14192 KB |
Output is correct |
41 |
Correct |
155 ms |
14372 KB |
Output is correct |
42 |
Correct |
167 ms |
14408 KB |
Output is correct |
43 |
Correct |
156 ms |
14408 KB |
Output is correct |
44 |
Correct |
146 ms |
13900 KB |
Output is correct |
45 |
Correct |
151 ms |
14136 KB |
Output is correct |
46 |
Correct |
148 ms |
13936 KB |
Output is correct |
47 |
Correct |
150 ms |
14248 KB |
Output is correct |
48 |
Correct |
164 ms |
14160 KB |
Output is correct |
49 |
Correct |
188 ms |
14704 KB |
Output is correct |
50 |
Correct |
161 ms |
14648 KB |
Output is correct |
51 |
Correct |
168 ms |
14680 KB |
Output is correct |
52 |
Correct |
155 ms |
15076 KB |
Output is correct |
53 |
Correct |
160 ms |
14872 KB |
Output is correct |