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;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> A(n+1), B(n);
for(int i = 0; i <= n; i++)
cin >> A[i];
for(int i = 0; i < n; i++)
cin >> B[i];
sort(B.begin(), B.end());
vector<pair<int, int>> C(n+1);
for(int i = 0; i <= n; i++)
C[i] = {A[i], i};
sort(C.begin(), C.end());
multiset<pair<int, int>> maxdiff;
vector<int> ans(n+1);
for(int i = 0; i < n; i++){
maxdiff.insert({-abs(B[i]-C[i].first), B[i]});
}
ans[C[n].second] = maxdiff.begin()->first;
for(int j = n-1; j >= 0; --j){
int original = -abs(B[j]-C[j].first);
maxdiff.erase(maxdiff.find({original, B[j]}));
maxdiff.insert({-abs(B[j]-C[j+1].first), B[j]});
ans[C[j].second] = maxdiff.begin()->first;
}
for(int i : ans)
cout << -i << ' ';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |