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;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
ll ans[n+1];
int ind[n+2];
ll a[n+2],b[n+1];
multiset<ll> c;
for(int i = 0;i < n+1;++i)
{
cin >> a[i];
ind[i] = i;
}
sort(ind,ind + n + 1,[&](int x,int y){return a[x] < a[y];});
for(int i = 0;i < n;++i)
cin >> b[i];
sort(b,b+n);
for(int i = 0;i < n;++i)
{
c.insert(-max(0ll,a[ind[i+1]] - b[i]));
}
for(int i =0;i < n;++i)
{
ans[ind[i]] = -(*c.begin());
c.erase(c.find(-max(0ll,a[ind[i+1]] - b[i])));
c.insert(-max(0ll,a[ind[i]] - b[i]));
}
ans[ind[n]] = -(*c.begin());
for(auto c:ans)
cout << c << ' ';
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... |