This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define int long long
const int maxn = 5e5+10;
int a[maxn], b[maxn], pr[maxn], sf[maxn], n;
vector<pair<int,int>> A, B;
int ans[maxn];
signed main()
{
cin>> n;
for(int i = 1; i <= n+1; i++)
{
cin>> a[i];
A.push_back({a[i],i});
}
for(int i = 1; i <= n; i++)
{
cin>> b[i];
B.push_back({b[i],i});
}
sort(A.begin(), A.end());
sort(B.begin(), B.end());
for(int i = 1; i <= n; i++)
pr[i] = max(pr[i-1], A[i-1].F-B[i-1].F);
for(int i = n+1; i >= 2; i--)
sf[i] = max(sf[i+1], A[i-1].F-B[i-2].F);
for(int i = 1; i <= n+1; i++)
ans[A[i-1].S] = max(sf[i+1], pr[i-1]);
for(int i = 1; i <= n+1; i++)
cout<< ans[i] <<" ";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |