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 f first
#define s second
#define pb push_back
using namespace std;
const int N=3e5+5;
long long n,idx[N],a[N],b[N],pr1[N],pr2[N],x[N],xx[N],sf1[N],sf2[N],ans[N];
int main() {
cin>>n;
for (int i=1; i<=n+1; i++) {
cin>>a[i];
idx[a[i]]=i;
//ms.insert(a[i]);
}
sort(a+1, a+n+2);
for (int i=1; i<=n; i++) {
cin>>b[i];
}
sort(b+1, b+n+1);
for (int i=1; i<=n; i++) {
x[i]=max(0LL, a[i]-b[i]);
xx[i]=max(0LL, a[i+1]-b[i]);
pr1[i]=max(pr1[i-1],x[i]);
pr2[i]=max(pr2[i-1],x[i]);
}
for (int i=n; i>=1; i--) {
sf1[i]=max(x[i],sf1[i+1]);//sf1[i+1]+x[i];
sf2[i]=max(sf2[i+1],xx[i]);
}
// cout<<sf2[2]<<endl;
for (int i=1; i<=n+1; i++) {
ans[idx[a[i]]]=max(sf2[i],pr1[i-1]);
}
for (int 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... |