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;
#define int long long
int n,b[200005];
pair<int,int> a[200005];
int ans[200005];
int d1[200005],d2[200005];
int maxpref[200005],maxsuf[200005];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n + 1; i++)
cin >> a[i].first,a[i].second = i;
for (int i = 1; i <= n; i++)
cin >> b[i];
sort(b + 1,b + n + 1);
sort(a + 1,a + n + 2);
for (int i = 1; i <= n; i++)
d1[i] = abs(a[i].first - b[i]);
for (int i = 1; i <= n; i++)
d2[i] = abs(a[i + 1].first - b[i]);
maxpref[0] = 0;
maxsuf[n + 1] = 0;
for (int i = 1; i <= n; i++)
maxpref[i] = max(maxpref[i - 1],abs(a[i].first - b[i]));
for (int i = n; i >= 1; i--)
maxsuf[i] = max(maxsuf[i + 1],abs(a[i + 1].first - b[i]));
for (int i = 1; i <= n + 1; i++)
ans[a[i].second] = max(maxpref[i - 1],maxsuf[i]);
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... |