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
using namespace std;
ll a,b,c,d,i,e,f,g,n,m,k,l;
ll B[500005],C[500005],D[500005],ans[500005];
pair <ll,ll> A[500005];
string s[5003];
int main() {
cin>>n;
for(ll i=1;i<=n+1;i++) {
cin>>A[i].first;
A[i].second=i;
}
sort(A+1,A+1+n+1);
for(ll i=1;i<=n;i++) {
cin>>B[i];
}
sort(B+1,B+1+n);
for(ll i=1;i<=n;i++) {
C[i]=max(C[i-1],max(0ll,A[i].first-B[i]));
}
for(ll i=n;i>=1;i--) {
D[i]=max(D[i+1],max(0ll,A[i+1].first-B[i]));
//cout<<D[i]<<" ";
}
//cout<<endl;
for(ll i=1;i<=n+1;i++) {
//cout<<C[i-1]<<" "<<D[i]<<endl;
ans[A[i].second]=max(C[i-1],D[i]);
}
for(ll i=1;i<=n+1;i++) {
cout<<ans[i]<<" ";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |