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 int long long
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n; cin >> n;
vector<pair<int,int>> a(n+2),b(n+1);
for(int i=1;i<=n+1;++i) cin >> a[i].first;
for(int i=1;i<=n;++i) cin >> b[i].first;
for(int i=1;i<=n+1;++i) a[i].second=i;
sort(a.begin()+1,a.end());
sort(b.begin()+1,b.end());
vector<int> Lans(n+5,-1e18),Rans(n+5,-1e18);
for(int i=1;i<=n;++i){
Lans[i]=max(Lans[i-1],max(0LL,a[i].first-b[i].first));
// cout << "Lans" << Lans[i] << '\n';
}
for(int i=n+1;i>=2;--i){
Rans[i]=max(Rans[i+1],max(0LL,a[i].first-b[i-1].first));
// cout << "Rans" << Rans[i] << '\n';
}
vector<int> ans(n+1);
for(int i=1;i<=n+1;++i){
ans[a[i].second]=max(Lans[i-1],Rans[i+1]);
// cout << "a[i].second" << a[i].second << '\n';
}
for(int i=1;i<=n+1;++i)
cout << ans[i] << '\n';
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... |