#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
vector<pair<int, int>> a(n+1);
vector<int> b(n);
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> suf(n+2, 0);
vector<int> ans(n+1);
for (int i = n; i >= 1; --i) suf[i] = max(suf[i+1], max(0, a[i].first - b[i-1]));
int ye = 0;
for (int i = 1; i <= n+1; ++i)
{
ans[a[i-1].second] = max(ye, suf[i]);
ye = max(ye, max(0, a[i-1].first - b[i-1]));
}
for (auto i : ans) cout << 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... |