#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
const int maxn = 1e6+5;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
pair<int, int> a[maxn];
for (int i = 1; i <= n+1; i++){
cin >> a[i].fi;
a[i].se = i;
}
int b[maxn];
for (int i = 1; i <= n; i++) cin >> b[i];
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
int prefix[maxn], suffix[maxn];
for (int i = 1; i <= n; i++) prefix[i] = max(prefix[i-1], a[i].fi - b[i]);
for (int i = n; i >= 1; i--) suffix[i] = max(suffix[i+1], a[i+1].fi - b[i]);
int kq[maxn];
for (int i = 1; i <= n+1; i++) kq[a[i].se] = max(prefix[i-1], suffix[i]);
for (int i = 1; i <= n+1; i++) cout << kq[i] << ' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
47188 KB |
Output is correct |
2 |
Correct |
21 ms |
47280 KB |
Output is correct |
3 |
Correct |
18 ms |
47188 KB |
Output is correct |
4 |
Correct |
17 ms |
47164 KB |
Output is correct |
5 |
Correct |
17 ms |
47188 KB |
Output is correct |
6 |
Correct |
17 ms |
47188 KB |
Output is correct |
7 |
Correct |
18 ms |
47212 KB |
Output is correct |
8 |
Correct |
20 ms |
47252 KB |
Output is correct |
9 |
Correct |
22 ms |
47236 KB |
Output is correct |
10 |
Correct |
17 ms |
47188 KB |
Output is correct |
11 |
Correct |
16 ms |
47188 KB |
Output is correct |
12 |
Correct |
17 ms |
47272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
47188 KB |
Output is correct |
2 |
Correct |
21 ms |
47280 KB |
Output is correct |
3 |
Correct |
18 ms |
47188 KB |
Output is correct |
4 |
Correct |
17 ms |
47164 KB |
Output is correct |
5 |
Correct |
17 ms |
47188 KB |
Output is correct |
6 |
Correct |
17 ms |
47188 KB |
Output is correct |
7 |
Correct |
18 ms |
47212 KB |
Output is correct |
8 |
Correct |
20 ms |
47252 KB |
Output is correct |
9 |
Correct |
22 ms |
47236 KB |
Output is correct |
10 |
Correct |
17 ms |
47188 KB |
Output is correct |
11 |
Correct |
16 ms |
47188 KB |
Output is correct |
12 |
Correct |
17 ms |
47272 KB |
Output is correct |
13 |
Correct |
17 ms |
47204 KB |
Output is correct |
14 |
Correct |
17 ms |
47188 KB |
Output is correct |
15 |
Correct |
18 ms |
47208 KB |
Output is correct |
16 |
Correct |
19 ms |
47264 KB |
Output is correct |
17 |
Correct |
19 ms |
47188 KB |
Output is correct |
18 |
Correct |
18 ms |
47188 KB |
Output is correct |
19 |
Correct |
19 ms |
47188 KB |
Output is correct |
20 |
Correct |
19 ms |
47284 KB |
Output is correct |
21 |
Correct |
19 ms |
47268 KB |
Output is correct |
22 |
Correct |
19 ms |
47260 KB |
Output is correct |
23 |
Correct |
19 ms |
47276 KB |
Output is correct |
24 |
Correct |
18 ms |
47216 KB |
Output is correct |
25 |
Correct |
18 ms |
47224 KB |
Output is correct |
26 |
Correct |
18 ms |
47188 KB |
Output is correct |
27 |
Correct |
20 ms |
47216 KB |
Output is correct |
28 |
Correct |
18 ms |
47252 KB |
Output is correct |
29 |
Correct |
17 ms |
47188 KB |
Output is correct |
30 |
Correct |
18 ms |
47188 KB |
Output is correct |
31 |
Correct |
18 ms |
47280 KB |
Output is correct |
32 |
Correct |
21 ms |
47272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
47188 KB |
Output is correct |
2 |
Correct |
21 ms |
47280 KB |
Output is correct |
3 |
Correct |
18 ms |
47188 KB |
Output is correct |
4 |
Correct |
17 ms |
47164 KB |
Output is correct |
5 |
Correct |
17 ms |
47188 KB |
Output is correct |
6 |
Correct |
17 ms |
47188 KB |
Output is correct |
7 |
Correct |
18 ms |
47212 KB |
Output is correct |
8 |
Correct |
20 ms |
47252 KB |
Output is correct |
9 |
Correct |
22 ms |
47236 KB |
Output is correct |
10 |
Correct |
17 ms |
47188 KB |
Output is correct |
11 |
Correct |
16 ms |
47188 KB |
Output is correct |
12 |
Correct |
17 ms |
47272 KB |
Output is correct |
13 |
Correct |
17 ms |
47204 KB |
Output is correct |
14 |
Correct |
17 ms |
47188 KB |
Output is correct |
15 |
Correct |
18 ms |
47208 KB |
Output is correct |
16 |
Correct |
19 ms |
47264 KB |
Output is correct |
17 |
Correct |
19 ms |
47188 KB |
Output is correct |
18 |
Correct |
18 ms |
47188 KB |
Output is correct |
19 |
Correct |
19 ms |
47188 KB |
Output is correct |
20 |
Correct |
19 ms |
47284 KB |
Output is correct |
21 |
Correct |
19 ms |
47268 KB |
Output is correct |
22 |
Correct |
19 ms |
47260 KB |
Output is correct |
23 |
Correct |
19 ms |
47276 KB |
Output is correct |
24 |
Correct |
18 ms |
47216 KB |
Output is correct |
25 |
Correct |
18 ms |
47224 KB |
Output is correct |
26 |
Correct |
18 ms |
47188 KB |
Output is correct |
27 |
Correct |
20 ms |
47216 KB |
Output is correct |
28 |
Correct |
18 ms |
47252 KB |
Output is correct |
29 |
Correct |
17 ms |
47188 KB |
Output is correct |
30 |
Correct |
18 ms |
47188 KB |
Output is correct |
31 |
Correct |
18 ms |
47280 KB |
Output is correct |
32 |
Correct |
21 ms |
47272 KB |
Output is correct |
33 |
Correct |
82 ms |
48688 KB |
Output is correct |
34 |
Correct |
87 ms |
48852 KB |
Output is correct |
35 |
Correct |
83 ms |
48688 KB |
Output is correct |
36 |
Correct |
85 ms |
49196 KB |
Output is correct |
37 |
Correct |
89 ms |
49208 KB |
Output is correct |
38 |
Correct |
87 ms |
49200 KB |
Output is correct |
39 |
Correct |
85 ms |
48416 KB |
Output is correct |
40 |
Correct |
85 ms |
48336 KB |
Output is correct |
41 |
Correct |
85 ms |
48332 KB |
Output is correct |
42 |
Correct |
85 ms |
48416 KB |
Output is correct |
43 |
Correct |
84 ms |
48328 KB |
Output is correct |
44 |
Correct |
83 ms |
48160 KB |
Output is correct |
45 |
Correct |
84 ms |
48172 KB |
Output is correct |
46 |
Correct |
83 ms |
48392 KB |
Output is correct |
47 |
Correct |
83 ms |
47712 KB |
Output is correct |
48 |
Correct |
82 ms |
47780 KB |
Output is correct |
49 |
Correct |
88 ms |
48416 KB |
Output is correct |
50 |
Correct |
88 ms |
48416 KB |
Output is correct |
51 |
Correct |
86 ms |
48428 KB |
Output is correct |
52 |
Correct |
86 ms |
48360 KB |
Output is correct |
53 |
Correct |
88 ms |
48428 KB |
Output is correct |