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;
using ll = long long;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
ll n;
cin >> n;
vector<ll> a(n+1),b(n);
for(ll &i : a) cin >> i;
for(ll &i : b) cin >> i;
sort(b.begin(),b.end());
vector<pair<ll,ll>> c(n+1);
for(ll i = 0;i<=n;i++) c[i] = {a[i],i};
sort(c.begin(),c.end());
ll cur = 0;
vector<ll> ans(n+1);
for(ll i = 0;i<n;i++) cur = max({cur,0ll,c[i].first-b[i]});
for(ll i = n;i>=0;i--){
ans[c[i].second] = cur;
if(i){
cur = max({cur,0ll,c[i].first-b[i-1]});
}
}
for(ll i = 0;i<=n;i++) cout << ans[i] << " \n"[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... |