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 <algorithm>
using namespace std;
int n,b[200010],r[200010];
struct cravata{int val,poz;}a[200010],dif[200010];
bool comp1(cravata a,cravata b)
{
return a.val<b.val;
}
int main()
{
cin>>n;
for(int i=1;i<=n+1;++i)
{
cin>>a[i].val;
a[i].poz=i;
}
for(int i=1;i<=n;++i)
cin>>b[i];
sort(a+1,a+n+2,comp1);
sort(b+1,b+n+1);
for(int i=1;i<=n;++i)
{
dif[i].poz=i;
dif[i].val=max(0,a[i].val-b[i]);
}
sort(dif+1,dif+n+1,comp1);
r[a[n+1].poz]=dif[n].val;
int maxa=0,poza=n;
for(int i=n;i>=1;--i)
{
maxa=max(maxa,a[i+1].val-b[i]);
while(dif[poza].val>maxa&&dif[poza].poz>=i)
--poza;
r[a[i].poz]=max(maxa,dif[poza].val);
}
for(int i=1;i<=n+1;++i)
cout<<r[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... |