#include <bits/stdc++.h>
// Author: Kazuki_Will_Win_VOI_8703
#define fi first
#define se second
#define pii pair<int, int>
#define int long long
#define all(a) a.begin(), a.end()
using namespace std;
const int mn = 2e5 + 5, bm = (1 << 11) + 1, mod = 1e9 + 7, offset = 5e4;
const int inf = 1e18, base = 311;
int n, m, b[mn], prefix[mn], suffix[mn], ans[mn];
pii a[mn];
void solve(){
cin >> n;
for(int i = 1; i <= n + 1; i++){
cin >> a[i].fi; a[i].se = i;
}
for(int i = 1; i <= n; i++) cin >> b[i];
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
for(int i = 1; i <= n; i++){
prefix[i] = max({prefix[i - 1], a[i].fi - b[i], 0ll});
}
for(int i = n + 1; i >= 1; i--){
suffix[i] = max({suffix[i + 1], a[i].fi - b[i - 1], 0ll});
}
for(int i = 1; i <= n + 1; i++){
int id = a[i].se;
ans[id] = max(prefix[i - 1], suffix[i + 1]);
}
for(int i = 1; i <= n + 1; i++) cout << ans[i] << ' ';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while(t--){
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... |