#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define mp make_pair
#define Sz(x) (int)x.size()
using namespace std;
const int N = 2e5 + 5;
int n, a[N], b[N], pref[N], suf[N];
void solve() {
cin >> n;
vector <int> save;
for (int i = 1; i <= n + 1; i++) {
cin >> a[i];
save.push_back(a[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++) {
pref[i] = pref[i - 1];
pref[i] = max(pref[i], max(0ll, a[i] - b[i]));
}
for (int i = n + 1; i >= 2; i--) {
suf[i] = suf[i + 1];
suf[i] = max(suf[i], max(0ll, a[i] - b[i - 1]));
}
map <int,int> ans;
for (int i = 1; i <= n + 1; i++) {
ans[a[i]] = max(pref[i - 1], suf[i + 1]);
}
for (auto to : save) {
cout << ans[to] << ' ';
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int tt = 1;
// cin >> tt;
while (tt--) {
solve();
// cout << '\n';
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |