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 int ll;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define gcd __gcd
#define endl '\n'
const int N=200050,M=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;
pii a[N];
ll n, b[N], res[N], ans[N];
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(nullptr); cout.tie(nullptr);
cin>>n;
for(ll i=0; i<=n; ++i){
cin>>a[i].fi;
a[i].se=i;
}
for(ll i=0; i<n; ++i) cin>>b[i];
sort(a, a+n+1);
sort(b, b+n);
for(ll i=0; i<n; ++i)
res[i+1]=max(res[i], max(0LL, a[i].fi-b[i]));
// for(ll i=0; i<=n; ++i) cout<<res[i]<<" ";
// cout<<endl;
for(ll i=n; i; --i)
res[i-1]=max(res[i], max(0LL, a[i].fi-b[i-1]));
for(ll i=0; i<=n; ++i) ans[a[i].se]=res[i];
for(ll i=0; i<=n; ++i) cout<<ans[i]<<" ";
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... |