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;
#define ll long long
#define ARRS ((ll)(4e5+100))
#define fr first
#define sc second
#define pb push_back
#define MX ((ll)(1e9+100))
#define MAX ((ll)(1e18+100))
ll n;
pair<ll,ll> a[ARRS];
ll b[ARRS];
ll ans[ARRS];
int main(){
cin>>n;
for(int i=0; i<=n; i++){
cin>>a[i].fr;
a[i].sc=i;
}
for(int i=0; i<n; i++){
cin>>b[i];
}
sort(a,a+n+1);
sort(b,b+n);
multiset<ll> st;
for(int i=0; i<n; i++)
st.insert(a[i].fr-b[i]);
for(int i=n; i>=0; i--){
ans[a[i].sc]=*(--st.end());
if(i)
st.erase(st.find(a[i-1].fr-b[i-1]));
st.insert(a[i].fr-b[i-1]);
}
for(int i=0; i<=n; i++){
cout<<ans[i]<<" ";
}
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... |