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;
int main()
{
int n;
cin>>n;
vector<int> a(n+1);
vector<int> b(n);
vector<int> c(n+1);
for(int i = 0;i<n+1;i++)
{
cin>>a[i];
c[i] = a[i];
}
for(int i = 0;i<n;i++)
{
cin>>b[i];
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
long long su[n];
su[0] = max(a[0]-b[0],0);
for(int i = 1;i<n;i++)
{
su[i] = max(su[i-1],(long long)max(a[i]-b[i],0));
}
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
long long pr[n];
pr[0] = max(a[0] - b[0],0);
for(int i = 1;i<n;i++)
{
pr[i] = max(pr[i-1],(long long)max(a[i]-b[i],0));
}
unordered_map<int,long long> ans;
ans[a[0]] = su[n-1];
for(int i = 1;i<n;i++)
{
ans[a[i]] = max(pr[i-1], su[n-i-1]);
}
ans[a[n]] = pr[n-1];
for(int i = 0;i<n+1;i++)
{
cout<<ans[c[i]]<<" ";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |