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 int long long
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
pair<int,int> a[n+2];
int b[n+1];
int ans[n+2];
for(int i=1;i<=n+1;i++){
cin >> a[i].first;
a[i].second=i;
}
for(int i=1;i<=n;i++){
cin >> b[i];
}
sort(b+1,b+n+1);
sort(a+1,a+n+2);
int firstdiff[n+1];
multiset<int> s;
for(int i=1;i<=n;i++){
firstdiff[i]=max(0LL,a[i].first-b[i]);
}
int secoddiff[n+1];
for(int i=1;i<=n;i++){
secoddiff[i]=max(0LL,a[i+1].first-b[i]);
s.insert(secoddiff[i]);
}
for(int i=1;i<=n+1;i++){
auto it=s.end();
it--;
int x=*it;
ans[a[i].second]=x;
if(i==n+1){
break;
}
s.erase(s.find(secoddiff[i]));
s.insert(firstdiff[i]);
}
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... |