#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<pair<int, int>> a(n+2);
vector<int> b(n+1);
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(a.begin()+1, a.end());
sort(b.begin()+1, b.end());
vector<int> pref(n+5, 0), suff(n+5, 0);
for(int i = 1; i <= n; i++){
pref[i] = max(pref[i-1], a[i].first-b[i]);
}
for(int i = n+1; i >= 2; i--){
suff[i] = max(suff[i+1], a[i].first - b[i-1]);
}vector<int> ans(n+5);
for(int i = 1; i <= n+1; i++){
ans[a[i].second] = max(pref[i-1], suff[i+1]);
}
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... |