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>
#include <set>
using namespace std;
#define X first
#define Y second
int ans[200001];
int arr[200001];
multiset<int> ms;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int>> v;
for(int i = 0; i <= n; i++)
{
int x;
cin >> x;
v.push_back({x, i});
}
for(int i = 0; i < n; i++)
cin >> arr[i];
sort(v.begin(), v.end());
sort(arr, arr+n);
for(int i = 0; i < n; i++)
ms.insert(max(0, v[i].X-arr[i]));
ans[v[n].Y] = *ms.rbegin();
for(int i = n-1; i >= 0; i--)
{
ms.erase(ms.find(max(0, v[i].X-arr[i])));
ms.insert(max(0, v[i+1].X-arr[i]));
ans[v[i].Y] = *ms.rbegin();
}
for(int i = 0; i <= n; i++)
cout << ans[i] << ' ';
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... |