#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 42
#endif
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> b(n);
vector<pair<int, int>> a(n + 1);
for (int i = 0; i <= n; i++) {
cin >> a[i].first;
a[i].second = i;
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> ans(n + 1);
multiset<int> s;
for (int i = 1; i <= n; i++) {
s.insert(max(a[i].first - b[i - 1], 0LL));
}
ans[a[0].second] = *s.rbegin();
for (int i = 0; i < n; i++) {
s.insert(max(a[i].first - b[i], 0LL));
s.erase(s.find(max(a[i + 1].first - b[i], 0LL)));
ans[a[i + 1].second] = *s.rbegin();
}
for (int i = 0; i <= n; i++) {
cout << ans[i] << ' ';
}
cout << '\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... |