#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define int long long
#define fi first
#define se second
const int N = 3e5 + 5, M = 1e9 + 7, LG = 20;
int n , B[N] , px[N] , sm[N] , ans[N] , x;
void solve(){
cin >> n;
vector<pair<int,int>> a;
for (int i=0 ; i<=n ; i++){
cin >> x;
a.pb({x,i});
}
for (int i=0 ; i<n ; i++){
cin >> B[i];
}
sort(B,B+n);
sort(a.begin(),a.end());
for (int i=0 ; i<n ; i++){
px[i+1] = max(px[i] , a[i].fi-B[i]);
}
for (int i=n-1 ; i>=0 ; i--){
sm[i+2] = max(sm[i+3] , a[i+1].fi-B[i]);
}
for (int i=0 ; i<=n ; i++){
if (!i){
ans[a[i].se] = sm[i+2];
}else if (i==n){
ans[a[i].se] = px[i];
}else{
ans[a[i].se] = max(sm[i+2] , px[i]);
}
}
for (int i=0 ; i<=n ; i++){
cout << ans[i] << ' ';
}
cout << endl;
}
signed main(){
// freopen("" , "r" , stdin);
// freopen("" , "w" , stdout);
// cout << setprecision(30);
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int ts = 1;
// cin >> ts;
while(ts--){
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |