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 pii = pair<long long, int>;
const int N = 2e5+5;
pii a[N];
long long b[N], suf[N], ans[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for(int i=0; i<n+1; i++)
{
cin >> a[i].first;
a[i].second = i;
}
for(int i=0; i<n; i++)
cin >> b[i];
sort(b, b+n);
sort(a, a+n+1);
for(int i=n; i>0; i--)
suf[i] = max(suf[i+1], a[i].first - b[i-1]);
ans[a[0].second] = suf[1];
long long now = max(a[0].first - b[0], 0LL);
for(int i=1; i<n+1; i++)
{
ans[a[i].second] = max({now, suf[i+1]});
now = max(now, a[i].first - b[i]);
}
for(int i=0; i<n+1; i++)
cout << ans[i] << " ";
cout << "\n";
}
/*
3
4 3 7 6
2 6 4
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |