#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define f first
#define s second
const int maxn = 200001, k = 18;
int n;
pi a[maxn];
int b[maxn], lg[maxn];
int st[2][k][maxn];
int ans[maxn];
int mx(int t, int l, int r){
if(l > r) return 0;
int z = lg[r - l + 1];
return max(st[t][z][l], st[t][z][r - (1 << z) + 1]);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i <= n; i++){
cin >> a[i].f;
a[i].s = i;
}
for(int i = 0; i < n; i++) cin >> b[i];
sort(a, a + n + 1);
sort(b, b + n);
for(int i = 0; i < n; i++){
st[0][0][i] = max(a[i].f - b[i], 0);
st[1][0][i] = max(a[i + 1].f - b[i], 0);
}
for(int t = 0; t < 2; t++)
for(int i = 1; i < k; i++)
for(int j = 0; j + (1 << i) <= n; j++){
st[t][i][j] = max(st[t][i - 1][j], st[t][i - 1][j + (1 << (i - 1))]);
}
lg[1] = 0;
for(int i = 2; i <= n; i++) lg[i] = lg[i - 1] + (1 << (lg[i - 1] + 1) == i);
for(int i = 0; i <= n; i++){
ans[a[i].s] = max(mx(0, 0, i - 1), mx(1, i, n - 1));
}
cout << ans[0];
for(int i = 1; i <= n; i++) cout << " " << ans[i];
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
664 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
5 ms |
632 KB |
Output is correct |
20 |
Correct |
6 ms |
632 KB |
Output is correct |
21 |
Correct |
6 ms |
632 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
5 ms |
632 KB |
Output is correct |
24 |
Correct |
5 ms |
632 KB |
Output is correct |
25 |
Correct |
6 ms |
632 KB |
Output is correct |
26 |
Correct |
6 ms |
632 KB |
Output is correct |
27 |
Correct |
6 ms |
632 KB |
Output is correct |
28 |
Correct |
6 ms |
632 KB |
Output is correct |
29 |
Correct |
6 ms |
632 KB |
Output is correct |
30 |
Correct |
5 ms |
632 KB |
Output is correct |
31 |
Correct |
6 ms |
632 KB |
Output is correct |
32 |
Correct |
6 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
664 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
5 ms |
632 KB |
Output is correct |
20 |
Correct |
6 ms |
632 KB |
Output is correct |
21 |
Correct |
6 ms |
632 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
5 ms |
632 KB |
Output is correct |
24 |
Correct |
5 ms |
632 KB |
Output is correct |
25 |
Correct |
6 ms |
632 KB |
Output is correct |
26 |
Correct |
6 ms |
632 KB |
Output is correct |
27 |
Correct |
6 ms |
632 KB |
Output is correct |
28 |
Correct |
6 ms |
632 KB |
Output is correct |
29 |
Correct |
6 ms |
632 KB |
Output is correct |
30 |
Correct |
5 ms |
632 KB |
Output is correct |
31 |
Correct |
6 ms |
632 KB |
Output is correct |
32 |
Correct |
6 ms |
632 KB |
Output is correct |
33 |
Correct |
124 ms |
30584 KB |
Output is correct |
34 |
Correct |
134 ms |
31864 KB |
Output is correct |
35 |
Correct |
131 ms |
30712 KB |
Output is correct |
36 |
Correct |
127 ms |
31352 KB |
Output is correct |
37 |
Correct |
134 ms |
32376 KB |
Output is correct |
38 |
Correct |
129 ms |
31992 KB |
Output is correct |
39 |
Correct |
131 ms |
30840 KB |
Output is correct |
40 |
Correct |
136 ms |
30820 KB |
Output is correct |
41 |
Correct |
128 ms |
30968 KB |
Output is correct |
42 |
Correct |
127 ms |
30968 KB |
Output is correct |
43 |
Correct |
129 ms |
30712 KB |
Output is correct |
44 |
Correct |
127 ms |
29944 KB |
Output is correct |
45 |
Correct |
124 ms |
30200 KB |
Output is correct |
46 |
Correct |
128 ms |
29944 KB |
Output is correct |
47 |
Correct |
122 ms |
30968 KB |
Output is correct |
48 |
Correct |
121 ms |
31072 KB |
Output is correct |
49 |
Correct |
135 ms |
31608 KB |
Output is correct |
50 |
Correct |
134 ms |
31736 KB |
Output is correct |
51 |
Correct |
132 ms |
31608 KB |
Output is correct |
52 |
Correct |
130 ms |
31608 KB |
Output is correct |
53 |
Correct |
138 ms |
31608 KB |
Output is correct |