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>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=3e5;
const ll inf=1e18;
const ll mod=1e9+7;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
#define rand rd
ll ans[maxN];
struct qq
{
ll x,id;
bool operator<(const qq&o)
{
return x<o.x;
}
}a[maxN];
ll b[maxN],suff[maxN],pre[maxN];
ll n;
void solve()
{
cin >> n;
for(int i=1;i<=n+1;i++) cin >> a[i].x,a[i].id=i;
for(int i=1;i<=n;i++) cin >> b[i];
sort(a+1,a+n+2);
sort(b+1,b+n+1);
suff[n+1]=0;
for(int i=n;i>=1;i--)
{
suff[i]=max(suff[i+1],a[i+1].x-b[i]);
}
pre[0]=0;
for(int i=1;i<=n;i++)
{
pre[i]=max(pre[i-1],a[i].x-b[i]);
}
for(int i=1;i<=n+1;i++)
{
ans[a[i].id]=max(suff[i],pre[i-1]);
}
for(int i=1;i<=n+1;i++)
{
cout << ans[i]<<' ';
}
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |