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"
using namespace std;
const int N=2e5+5;
int n,a[N],b[N];
int p[N],o[N],pf[N],sf[N];
int main() {
cin.tie(0)->sync_with_stdio(0),cin.exceptions(cin.failbit);
cin>>n;
for(int i=0;i<=n;i++)cin>>a[i],p[i]=i;
for(int i=0;i<n;i++)cin>>b[i];
sort(p,p+n+1,[&](int i,int j){return a[i]<a[j];});
for(int i=0;i<=n;i++)o[p[i]]=i;
sort(b,b+n);
for(int i=0;i<n;i++)pf[i]=max(i>0?pf[i-1]:0,max(a[p[i]]-b[i],0));
for(int i=n;i>=1;i--)sf[i]=max(i<n?sf[i+1]:0,max(a[p[i]]-b[i-1],0));
for(int i=0;i<=n;i++){
int j=o[i];
cout<<max(j>0?pf[j-1]:0,j<n?sf[j+1]:0)<<" \n"[i==n];
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |