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;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
const ll INF=3e18;
#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
//#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
#define pb push_back
ll pre[200005],suf[200005],ans[200005];
signed main()
{
MottoHayaku
ll n;
cin>>n;
vector<pll> a(n+1);
vector<ll> b(n);
rep(i,n+1)
{
cin>>a[i].F;
a[i].S=i;
}
rep(i,n)
{
cin>>b[i];
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
for(int i=n-1;i>=0;i--)
{
suf[i]=max(suf[i+1],a[i+1].F-b[i]);
}
ll cur=0;
rep(i,n+1)
{
ans[a[i].S]=max(cur,suf[i]);
if(i==n) break;
cur=max(cur,a[i].F-b[i]);
}
rep(i,n+1) 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... |