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;
int n;
pair<int, int> a[200005];
int b[200005];
int dpL[200005], dpR[200005];
int ans[200005];
int main()
{
cin>>n;
for(int i=1; i<=n+1; i++)
{
cin>>a[i].first;
a[i].second = i;
}
sort(a+1, a+n+2);
for(int i=1; i<=n; i++)
cin>>b[i];
sort(b+1, b+n+1);
for(int i=1; i<=n; i++)
dpL[i] = max(dpL[i-1], max(a[i].first - b[i], 0));
for(int i=n+1; i>=2; i--)
dpR[i] = max(dpR[i+1], max(a[i].first - b[i-1], 0));
for(int i=1; i<=n+1; i++)
ans[ a[i].second ] = max(dpL[i-1], dpR[i+1]);
for(int i=1; i<=n+1; 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... |