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), O(n+1), ans(n+1);
for(int i = 0; i <= n; i++){
cin >> A[i];
O[i] = i;
}
for(int i = 0; i < n; i++)
cin >> B[i];
sort(B.begin(), B.end());
sort(O.begin(), O.end(), [&](int i, int j){
return A[i] < A[j];
});
vector<int> pref(n+1), suf(n+1);
for(int i = 0; i < n; i++)
pref[i+1] = max(pref[i], abs(A[O[i]] - B[i]));
for(int i = n; i > 0; --i)
suf[i-1] = max(suf[i], abs(A[O[i]] - B[i-1]));
for(int i = 0; i < n+1; i++)
ans[O[i]] = max(pref[i], suf[i]);
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... |