// File neckties2.cpp created on 01.10.2025 at 08:45:42
#include <bits/stdc++.h>
using i64 = long long;
#ifdef DEBUG
#include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
#define debug(...) void(23)
#endif
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
std::cin >> N;
std::vector<int> A(N + 1), B(N);
for (int i = 0; i < N + 1; ++i) {
std::cin >> A[i];
}
for (int i = 0; i < N; ++i) {
std::cin >> B[i];
}
std::vector<int> p(N + 1);
std::iota(p.begin(), p.end(), 0);
std::sort(p.begin(), p.end(), [&](auto lhs, auto rhs) {
return A[lhs] < A[rhs];
});
std::sort(B.begin(), B.end());
std::vector<int> pre(N + 1), suf(N + 1);
for (int i = 0; i < N; ++i) {
pre[i + 1] = std::max(pre[i], A[p[i]] - B[i]);
}
for (int i = N - 1; i >= 0; --i) {
suf[i] = std::max(suf[i + 1], A[p[i + 1]] - B[i]);
}
std::vector<int> ans(N + 1);
for (int i = 0; i < int(p.size()); ++i) {
ans[p[i]] = std::max(pre[i], suf[i]);
}
for (int i = 0; i < N + 1; ++i) {
std::cout << ans[i] << " \n"[i == N];
}
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... |