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>
#define endl '\n'
using namespace std;
long long pref[1000000], suf[1000000], b[1000000], ans[1000000];
struct st
{
long long num, ind;
}a[1000000];
bool cmp(st a1, st a2)
{
return a1.num<a2.num;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n,i,j;
cin>>n;
for(i=1;i<=n+1;i++){cin>>a[i].num; a[i].ind=i;}
for(i=1;i<=n;i++)cin>>b[i];
sort(a+1,a+n+2,cmp);
sort(b+1,b+n+1);
for(i=1;i<=n+1;i++)
{
pref[i]=max(pref[i-1],(a[i].num-b[i]));
}
for(i=n;i>=1;i--)
{
suf[i]=max(suf[i+1],a[i+1].num-b[i]);
}
for(i=1;i<=n+1;i++)
{
ans[a[i].ind]=max(pref[i-1],suf[i]);
}
for(i=1;i<=n+1;i++)
{
cout<<ans[i]<<" ";
}cout<<endl;
}
Compilation message (stderr)
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:20:19: warning: unused variable 'j' [-Wunused-variable]
20 | long long n,i,j;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |