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<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#define ll long long
using namespace std;
int main(){
int n;
cin>>n;
vector<ll> b(n);
vector<pair<ll,ll>> a(n+1);
for(int i=0;i<=n;i++) cin>>a[i].first;
for(int i=0;i<n;i++) cin>>b[i];
sort(b.begin(),b.end());
for(int i=0;i<=n;i++) a[i].second=i;
sort(a.begin(),a.end());
vector<ll> ans(n+1);
multiset<ll> s;
for(int i=0;i<n;i++) s.insert(a[i+1].first-b[i]);
ans[a[0].second]=*prev(s.end());
for(int i=1;i<=n;i++){
s.erase(s.find(a[i].first-b[i-1]));
s.insert(a[i-1].first-b[i-1]);
ans[a[i].second]=*prev(s.end());
}
for(auto x:ans) cout<<x<<" ";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |