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;
typedef pair<int,int> ii;
int main(){
int n; cin>>n;
vector<ii> neck(n+1);
vector<int> ori(n);
int c=0;
for(auto &v:neck) {
cin>>v.first;
v.second=c++;
}
for(auto &v:ori) cin>>v;
sort(neck.begin(),neck.end());
sort(ori.begin(),ori.end());
vector<int> front(n),back(n);
for(int i=0;i<n;i++){
front[i]=max(
i>0?front[i-1]:0,
max(neck[i].first-ori[i],0));
}
for(int i=n-1;i>=0;i--){
back[i]=max(
i<n-1?back[i+1]:0,
max(neck[i+1].first-ori[i],0));
}
vector<int> ans(n+1);
for(int i=0;i<=n;i++){
ans[neck[i].second]=max(
i>0?front[i-1]:0,
i<n?back[i]:0);
}
for(auto &v:ans) cout<<v<<" ";
cout<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |