#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
//#define int long long
//#define ld long double
using namespace std;
using ll=long long;
const int inf = 1e18;
const int MN =200005;
const int mod=1e9+7;
int n;
pii a[MN];
int b[MN];
int ans[MN];
int st[4*MN];
void update(int id, int l, int r, int pos, int val) {
if(l==r) {
st[id]=val;
return;
}
int m=(l+r)/2;
if(pos<=m) update(id*2,l,m,pos,val);
else update(id*2+1,m+1,r,pos,val);
st[id]=max(st[id*2],st[id*2+1]);
}
int get(int id, int l, int r, int tl, int tr) {
if(tl>r||tr<l) return -inf;
if(tl<=l&&tr>=r) return st[id];
int m=(l+r)/2;
return max(get(id*2,l,m,tl,tr), get(id*2+1,m+1,r,tl,tr));
}
void solve() {
cin>>n;
for (int i=1; i<=n+1; i++) {
cin>>a[i].fi;
a[i].se=i;
}
for (int i=1; i<=n; i++) {
cin>>b[i];
}
sort(b+1,b+n+1);
sort(a+1,a+n+2);
for (int i=1; i<=n; i++) {
update(1,1,n,i,max(0,a[i+1].fi-b[i]));
ans[a[1].se]=st[1];
}
for (int i=2; i<=n+1; i++) {
update(1,1,n,i-1, max(0,a[i-1].fi-b[i-1]));
ans[a[i].se]=st[1];
}
for (int i=1; i<=n+1; i++) {
cout<<ans[i]<<" ";
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen(".inp", "r", stdin);
// freopen(".out", "w", stdout);
int t=1;
// cin>>t;
while(t--) {
solve();
}
}
Compilation message
ho_t1.cpp:12:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
12 | const int inf = 1e18;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
412 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
372 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
412 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
372 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
110 ms |
10444 KB |
Output is correct |
34 |
Correct |
109 ms |
10828 KB |
Output is correct |
35 |
Correct |
107 ms |
10564 KB |
Output is correct |
36 |
Correct |
110 ms |
10956 KB |
Output is correct |
37 |
Correct |
111 ms |
11300 KB |
Output is correct |
38 |
Correct |
114 ms |
11212 KB |
Output is correct |
39 |
Correct |
112 ms |
10444 KB |
Output is correct |
40 |
Correct |
107 ms |
10188 KB |
Output is correct |
41 |
Correct |
108 ms |
10340 KB |
Output is correct |
42 |
Correct |
107 ms |
10252 KB |
Output is correct |
43 |
Correct |
106 ms |
10208 KB |
Output is correct |
44 |
Correct |
105 ms |
9932 KB |
Output is correct |
45 |
Correct |
112 ms |
9980 KB |
Output is correct |
46 |
Correct |
113 ms |
9964 KB |
Output is correct |
47 |
Correct |
103 ms |
9888 KB |
Output is correct |
48 |
Correct |
105 ms |
9924 KB |
Output is correct |
49 |
Correct |
110 ms |
10512 KB |
Output is correct |
50 |
Correct |
118 ms |
10508 KB |
Output is correct |
51 |
Correct |
125 ms |
10436 KB |
Output is correct |
52 |
Correct |
110 ms |
10496 KB |
Output is correct |
53 |
Correct |
117 ms |
10464 KB |
Output is correct |