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 <iostream>
#include <vector>
#include <algorithm>
#define int int64_t
using namespace std;
signed main()
{
int n;
cin >> n;
vector<pair<int, int>> a(n + 1);
vector<pair<int, int>> b(n);
for(int i = 0; i <= n; i ++)
{
cin >> a[i].first;
a[i].second = i;
}
for(int i = 0; i < n; i ++)
{
cin >> b[i].first;
b[i].second = i;
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> cl(n);
vector<int> cr(n);
for(int i = 0; i < n; i ++)
{
cl[i] = max(int(0), a[i].first - b[i].first);
cr[i] = max(int(0), a[i + 1].first - b[i].first);
}
vector<int> ml(n + 1);
vector<int> mr(n + 1);
int mlval = 0;
int mrval = 0;
for(int i = 1; i <= n; i ++)
{
mlval = max(mlval, cl[i - 1]);
ml[i] = mlval;
}
for(int i = n - 1; i >= 0; i --)
{
mrval = max(mrval, cr[i]);
mr[i] = mrval;
}
vector<int> ans0(n + 1);
for(int i = 0; i <= n; i ++) ans0[i] = max(ml[i], mr[i]);
vector<int> ans(n + 1);
for(int i = 0; i <= n; i ++) ans[a[i].second] = ans0[i];
for(int el : ans) cout << el << " ";
cout << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |