This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |