#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define pb push_back
#define nl '\n'
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector<int> a(n + 1), b(n);
for(auto &x : a) cin >> x;
for(auto &x : b) cin >> x;
vector<pair<int, int>> v(n + 1);
for(int i = 0; i <= n; i++) {
v[i] = {a[i], i};
}
sort(all(v)), sort(all(b));
vector<int> pref(n + 1), suf(n + 2);
for(int i = 0; i < n; i++) {
pref[i + 1] = max(pref[i], max(0LL, v[i].first - b[i]));
}
for(int i = n - 1; i >= 0; i--) {
suf[i] = max(suf[i], max(0LL, v[i + 1].first - b[i]));
}
// for(int i = 0; i <= n; i++) {
// cout << v[i].first << ' ';
// }
// cout << nl;
// for(int i = 0; i <= n; i++) {
// cout << v[i].second << ' ';
// }
// cout << nl;
// for(int i = 1; i <= n; i++) {
// cout << pref[i] << ' ';
// }
// cout << nl;
vector<int> ans(n + 1);
for(int i = 0; i <= n; i++) {
int res = 0;
for(int j = 0; j < i; j++) {
res = max(res, max(0LL, v[j].first - b[j]));
}
for(int j = n - 1; j >= i; j--) {
res = max(res, max(0LL, v[j + 1].first - b[j]));
}
ans[v[i].second] = res;
}
for(auto i : ans) cout << i << ' ';
cout << nl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |