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 LL long long
int n;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
vector<pair<LL,int>> a(n+1);
vector<LL> b(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(a.begin(), a.end());
sort(b.begin(), b.end());
vector<LL> left(n+1, 0), right(n+1, 0);
for (int i=0; i<n; i++)
{
left[i+1] = max(left[i], max(a[i].first-b[i], 0LL));
right[i+1] = max(right[i], max(a[n-i].first-b[n-i-1], 0LL));
}
vector<int> res(n+1);
for (int i=0; i<n+1; i++)
{
int id = a[i].second;
res[id] = max(left[i], right[n-i]);
}
for (int i = 0; i < n+1; i++)
{
if (i) cout << " ";
cout << res[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... |