#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int>> a;
vector<int> b(n);
for (int i = 0; i <= n; i++) {
int x;
cin >> x;
a.emplace_back(x, i);
}
for (int &i : b) cin >> i;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> l(n + 1), r(n + 1);
l[0] = a[0].first - b[0];
for (int i = 1; i < n; i++) {
l[i] = max(l[i - 1], a[i].first - b[i]);
}
r[n] = a[n].first - b[n - 1];
for (int i = n - 1; i > 0; i--) {
r[i] = max(r[i + 1], a[i].first - b[i - 1]);
}
vector<int> ans(n + 1);
ans[a[0].second] = r[1];
ans[a[n].second] = l[n - 1];
for (int i = 1; i < n; i++) {
ans[a[i].second] = max(r[i + 1], l[i - 1]);
}
for (int i : ans) cout << max(0, i) << ' ';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |