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;
const int Nmax = 2e5 + 5;
int dp1[Nmax], dp2[Nmax], A[Nmax], B[Nmax], ans[Nmax];
pair<int,int> ord[Nmax];
int n;
int main()
{
// freopen("input", "r", stdin);
cin.sync_with_stdio(false); cin.tie(0);
cin >> n;
int i;
for(i=1; i<=n+1; ++i) cin >> ord[i].first, ord[i].second = i;
for(i=1; i<=n; ++i) cin >> B[i];
sort(B+1, B+n+1);
sort(ord+1, ord+n+2);
for(i=1; i<=n+1; ++i) A[i] = ord[i].first;
for(i=1; i<=n; ++i)
dp1[i] = max(dp1[i-1], A[i] - B[i]);
for(i=n+1; i>=2; --i)
dp2[i] = max(dp2[i+1], A[i] - B[i-1]);
for(i=1; i<=n+1; ++i)
ans[ord[i].second] = max(dp1[i-1], dp2[i+1]);
for(i=1; i<=n+1; ++i) cout << ans[i] << ' ';
cout << '\n';
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... |