#include<bits/stdc++.h>
#define fi first
#define si second
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
using namespace std;
const int N = 1e6;
int n,b[N],pre[N],suf[N],ans[N];
pair<int,int> a[N];
int main()
{
cin >> n;
For(i,1,n+1) cin >> a[i].fi, a[i].si = i;
For(i,1,n) cin >> b[i];
sort(b+1,b+n+1);
sort(a+1,a+n+2);
for(int i = 1; i <= n; i++) pre[i] = max(pre[i-1],a[i].fi-b[i]);
for(int i = n; i >= 1; i--) suf[i] = max(suf[i+1],a[i+1].fi-b[i]);
for(int i = 1; i <= n+1; i++)
{
ans[a[i].si] = max(pre[i-1],suf[i]);
}
for(int i = 1; i <= n + 1; i++) cout << ans[i] <<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |