#include <bits/stdc++.h>
using namespace std;
pair<int, int> A[200005];
int B[200005];
int M1[200005];
int M2[200005];
int pref[200005];
int suf[200005];
int res[200005];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for(int i = 0; i <= n; i++){
cin >> A[i].first;
A[i].second = i;
}
for(int i = 0; i < n; i++) cin >> B[i];
sort(B, B+n);
sort(A, A+n+1);
for(int i = 0; i < n; i++) {
M1[i] = max(0, A[i].first - B[i]);
M2[i] = max(0, A[i+1].first - B[i]);
//cout << M1[i] << " " << M2[i] << '\n';
}
pref[0] = M1[0];
for(int i = 1; i < n; i++) {
pref[i] = max(pref[i-1], M1[i]);
//cout << pref[i] << " ";
}
//cout << '\n';
for(int i = n-1; i >= 0; i--) {
suf[i] = max(suf[i+1], M2[i]);
//cout << suf[i] << " ";
}
//cout << '\n';
res[A[n].second] = pref[n-1];
res[A[0].second] = suf[0];
for(int i = 1; i < n; i++){
res[A[i].second] = max(pref[i-1], suf[i]);
}
for(int i = 0; i <= n; i++) cout << res[i] << " ";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4568 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4568 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4572 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4440 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4468 KB |
Output is correct |
26 |
Correct |
1 ms |
4440 KB |
Output is correct |
27 |
Correct |
1 ms |
4440 KB |
Output is correct |
28 |
Correct |
1 ms |
4440 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4572 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4568 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4572 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4440 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4468 KB |
Output is correct |
26 |
Correct |
1 ms |
4440 KB |
Output is correct |
27 |
Correct |
1 ms |
4440 KB |
Output is correct |
28 |
Correct |
1 ms |
4440 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4572 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
65 ms |
11636 KB |
Output is correct |
34 |
Correct |
74 ms |
12112 KB |
Output is correct |
35 |
Correct |
62 ms |
11688 KB |
Output is correct |
36 |
Correct |
63 ms |
12112 KB |
Output is correct |
37 |
Correct |
66 ms |
12428 KB |
Output is correct |
38 |
Correct |
66 ms |
12368 KB |
Output is correct |
39 |
Correct |
64 ms |
11344 KB |
Output is correct |
40 |
Correct |
84 ms |
11344 KB |
Output is correct |
41 |
Correct |
63 ms |
11600 KB |
Output is correct |
42 |
Correct |
66 ms |
11452 KB |
Output is correct |
43 |
Correct |
62 ms |
11348 KB |
Output is correct |
44 |
Correct |
61 ms |
11092 KB |
Output is correct |
45 |
Correct |
61 ms |
11224 KB |
Output is correct |
46 |
Correct |
60 ms |
11088 KB |
Output is correct |
47 |
Correct |
61 ms |
10940 KB |
Output is correct |
48 |
Correct |
58 ms |
11092 KB |
Output is correct |
49 |
Correct |
78 ms |
11600 KB |
Output is correct |
50 |
Correct |
64 ms |
11596 KB |
Output is correct |
51 |
Correct |
62 ms |
11660 KB |
Output is correct |
52 |
Correct |
64 ms |
11596 KB |
Output is correct |
53 |
Correct |
64 ms |
11600 KB |
Output is correct |