#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n, m, r, x, y, i,p, j,cnt1,cnt, t,s, mx, mn, k;
cin >> n;
pair < ll, ll > P[n + 2];
for (i = 1; i <= n + 1; i ++) {
cin >> P[i].first;
P[i].second = i;
}
ll b[n + 2];
for (i = 1; i <= n; i++) {
cin >> b[i];
}
sort(b + 1, b + n + 1);
sort(P + 1, P + n + 2);
ll aragsh[n + 2], uragsh[n +2];
aragsh[n + 1] = uragsh[0] = 0;
for (i = n; i >= 1; i --) {
aragsh[i] = max(aragsh[i + 1], max(0ll, P[i + 1].first - b[i]));
}
for (i = 1; i <= n; i ++) {
uragsh[i] = max(uragsh[i - 1], max(0ll, P[i].first - b[i]));
}
ll ans[n + 2];
for (i = 1; i <= n + 1; i ++) {
s= max(uragsh[i - 1] , aragsh[i]);
ans[P[i].second] = s;
}
for (i= 1; i <= n + 1; i ++) cout << ans[i] << " ";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |