#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
signed main ()
{
cin.tie(0)->sync_with_stdio(0);ios_base::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
pair<int, int> a[n + 5], b[n + 5];
for(int i=0; i<=n; i++)
{
cin>>a[i].first;
a[i].second = i + 1;
}
for(int i=0; i<n; i++)
{
cin>>b[i].first;
b[i].second = i + 1;
}
sort(a, a+n+1);
sort(b, b+n);
int p[n + 5] = {}, s[n + 5] = {};
s[a[n].second] = 0, p[a[0].second] = 0;
for(int i=1; i<=n; i++) p[a[i].second] = max(p[a[i - 1].second], max(a[i - 1].first - b[i - 1].first, 0ll));
for(int i=n-1; i>=0; i--) s[a[i].second] = max(s[a[i + 1].second], max(a[i + 1].first - b[i].first, 0ll));
for(int i=0; i<=n; i++)
{
cout<<max(p[a[i].second], s[a[i].second])<<" ";
}
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... |