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 MX=2e5+5;
int N;
int A[MX], B[MX], pf[MX], sf[MX], ans[MX], rev[MX];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin>>N;
for(int i=1;i<=N+1;i++) cin>>A[i];
for(int i=1;i<=N;i++) cin>>B[i];
vector<int> ordA,ordB;
for(int i=1;i<=N+1;i++) ordA.push_back(i);
for(int i=1;i<=N;i++) ordB.push_back(i);
sort(ordA.begin(),ordA.end(),[&](int i, int j){
return A[i]<A[j];
});
sort(ordB.begin(),ordB.end(),[&](int i, int j){
return B[i]<B[j];
});
for(int i=1;i<=N;i++) {
int x=ordA[i-1],y=ordB[i-1];
pf[i]=max(pf[i-1],max(0,A[x]-B[y]));
}
for(int i=N+1;i>1;i--) {
int x=ordA[i-1],y=ordB[i-2];
sf[i]=max(sf[i+1],max(0,A[x]-B[y]));
}
for(int i=1;i<=N+1;i++) {
ans[i]=max(pf[i-1],sf[i+1]);
}
int p=1;
for(auto x:ordA) {
rev[x]=p;
p++;
}
for(int i=1;i<=N+1;i++) {
cout<<ans[rev[i]]<<" ";
}
cout<<'\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... |