#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+3;
int st[4*N];
struct wind{
int ind;
int val;
};
wind a[N];
int b[N];
bool cmp(wind A, wind B){
return A.val<B.val;
}
void Build(int node, int l, int r){
if(l>r)return;
if(l==r){
st[node]=max(0, a[l+1].val-b[l]);
return;
}
int mid=(l+r)/2;
Build(2*node+1, l, mid);
Build(2*node+2, mid+1, r);
st[node]=max(st[2*node+1], st[2*node+2]);
}
void Update(int node, int l, int r, int ind){
if(l>r || l>ind || r<ind)return;
if(l==r){
st[node]=max(a[l].val-b[l], 0);
return;
}
int mid=(l+r)/2;
Update(2*node+1, l, mid, ind);
Update(2*node+2, mid+1, r, ind);
st[node]=max(st[2*node+1], st[2*node+2]);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for(int i=0; i< n+1; i++){
cin >> a[i].val;
a[i].ind=i;
}
for(int i=0; i< n; i++){
cin >> b[i];
}
sort(a, a+n+1, cmp);
sort(b, b+n);
Build(0, 0, n-1);
int ans[n+1];
ans[a[0].ind]=st[0];
for(int i=1; i<=n; i++){
Update(0, 0, n-1, i-1);
ans[a[i].ind]=st[0];
}
for(int i=0; i<=n; i++){
cout << ans[i] << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 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 |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 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 |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4440 KB |
Output is correct |
17 |
Correct |
2 ms |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
2 ms |
4440 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 |
4440 KB |
Output is correct |
23 |
Correct |
1 ms |
4440 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
2 ms |
4440 KB |
Output is correct |
27 |
Correct |
2 ms |
4440 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4440 KB |
Output is correct |
30 |
Correct |
2 ms |
4440 KB |
Output is correct |
31 |
Correct |
1 ms |
4440 KB |
Output is correct |
32 |
Correct |
1 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 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 |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4440 KB |
Output is correct |
17 |
Correct |
2 ms |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
2 ms |
4440 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 |
4440 KB |
Output is correct |
23 |
Correct |
1 ms |
4440 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
2 ms |
4440 KB |
Output is correct |
27 |
Correct |
2 ms |
4440 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4440 KB |
Output is correct |
30 |
Correct |
2 ms |
4440 KB |
Output is correct |
31 |
Correct |
1 ms |
4440 KB |
Output is correct |
32 |
Correct |
1 ms |
4696 KB |
Output is correct |
33 |
Correct |
101 ms |
10676 KB |
Output is correct |
34 |
Correct |
100 ms |
10832 KB |
Output is correct |
35 |
Correct |
98 ms |
10600 KB |
Output is correct |
36 |
Correct |
98 ms |
11140 KB |
Output is correct |
37 |
Correct |
104 ms |
11348 KB |
Output is correct |
38 |
Correct |
107 ms |
11204 KB |
Output is correct |
39 |
Correct |
100 ms |
10320 KB |
Output is correct |
40 |
Correct |
109 ms |
10464 KB |
Output is correct |
41 |
Correct |
101 ms |
10540 KB |
Output is correct |
42 |
Correct |
110 ms |
10320 KB |
Output is correct |
43 |
Correct |
101 ms |
10256 KB |
Output is correct |
44 |
Correct |
104 ms |
10064 KB |
Output is correct |
45 |
Correct |
100 ms |
10064 KB |
Output is correct |
46 |
Correct |
98 ms |
10064 KB |
Output is correct |
47 |
Correct |
85 ms |
9908 KB |
Output is correct |
48 |
Correct |
96 ms |
10044 KB |
Output is correct |
49 |
Correct |
104 ms |
10632 KB |
Output is correct |
50 |
Correct |
103 ms |
10636 KB |
Output is correct |
51 |
Correct |
105 ms |
10508 KB |
Output is correct |
52 |
Correct |
104 ms |
10572 KB |
Output is correct |
53 |
Correct |
104 ms |
10576 KB |
Output is correct |