#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int32_t main() {
int n;
cin >> n;
vector<pii> a(n+1); int id = 0;
vector<int> b(n), ans(n+1);
for(auto &x : a) cin >> x.first, x.second = id++;
for(int &x : b) cin >> x;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> pref(n+1), suf(n+1);
pref[0] = a[0].first - b[0];
suf[n] = a[n].first - b[n-1];
for(int i=1; i<n+1; i++) pref[i] = max({ pref[i-1], 0, a[i].first - b[i] });
for(int i=n-1; i>=1; i--) suf[i] = max({ suf[i+1], 0, a[i].first - b[i-1] });
for(int i=0; i<=n; i++) {
int res = 0;
if(i) res = pref[i-1];
if(i != n) res = max(res, suf[i+1]);
ans[a[i].second] = res;
}
for(int &x : ans) cout << x << " ";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
356 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
356 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
144 ms |
6216 KB |
Output is correct |
34 |
Correct |
151 ms |
10292 KB |
Output is correct |
35 |
Correct |
155 ms |
9944 KB |
Output is correct |
36 |
Correct |
145 ms |
10576 KB |
Output is correct |
37 |
Correct |
210 ms |
10948 KB |
Output is correct |
38 |
Correct |
165 ms |
10644 KB |
Output is correct |
39 |
Correct |
146 ms |
9856 KB |
Output is correct |
40 |
Correct |
144 ms |
9848 KB |
Output is correct |
41 |
Correct |
146 ms |
9880 KB |
Output is correct |
42 |
Correct |
144 ms |
9740 KB |
Output is correct |
43 |
Correct |
145 ms |
9720 KB |
Output is correct |
44 |
Correct |
142 ms |
9296 KB |
Output is correct |
45 |
Correct |
146 ms |
9552 KB |
Output is correct |
46 |
Correct |
169 ms |
9400 KB |
Output is correct |
47 |
Correct |
142 ms |
9440 KB |
Output is correct |
48 |
Correct |
155 ms |
9552 KB |
Output is correct |
49 |
Correct |
148 ms |
10068 KB |
Output is correct |
50 |
Correct |
148 ms |
9936 KB |
Output is correct |
51 |
Correct |
155 ms |
9948 KB |
Output is correct |
52 |
Correct |
151 ms |
10072 KB |
Output is correct |
53 |
Correct |
185 ms |
9956 KB |
Output is correct |