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>
#define ll long long
#define ff first
#define ss second
#define db double
using namespace std;
ll n;
pair<ll,ll> a[200003];
ll b[200003];
ll mxpref[200003],mxsuf[200003];
int main(){
cin>>n;
for(ll k=1;k<=n+1;k++){
cin>>a[k].ff;
a[k].ss=k;
}
for(ll k=1;k<=n;k++){
cin>>b[k];
}
sort(a+1,a+n+2);
sort(b+1,b+n+1);
ll mx=0,cur;
for(ll k=1;k<=n;k++){
cur=max(0LL,a[k].ff-b[k]);
mx=max(mx,cur);
mxpref[k]=mx;
}
mx=0;
for(ll k=n;k>=1;k--){
cur=max(0LL,a[k+1].ff-b[k]);
mx=max(mx,cur);
mxsuf[k]=mx;
}
ll mx1=0,mx2=0;
ll ans[n+2];
for(ll k=1;k<=n+1;k++){
mx1=mxpref[k-1];
mx2=mxsuf[k];
ans[a[k].ss]=max(mx1,mx2);
}
for(int k=1;k<=n+1;k++)
cout<<ans[k]<<' ';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |