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(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int>>a(n + 2);
vector<int> b(n + 1);
for(int i = 1;i <= n + 1;++i){
cin >> a[i].first;
a[i].second = i;
}
sort(a.begin(), a.end());
for(int i = 1;i <= n;++i){
cin >> b[i];
}
sort(b.begin(), b.end());
vector<int>pref_mx(n + 1), suff_mx(n + 3);
for(int i = 1;i <= n;++i){
pref_mx[i] = pref_mx[i - 1];
pref_mx[i] = max({pref_mx[i], a[i].first - b[i], 0});
}
for(int i = n + 1;i >= 1;--i){
suff_mx[i] = suff_mx[i + 1];
suff_mx[i] = max({suff_mx[i], a[i].first - b[i - 1], 0});
}
vector<int>ans(n + 2);
for(int i = 1;i <= n + 1;++i){
ans[a[i].second] = max(pref_mx[i - 1], suff_mx[i + 1]);
}
for(int i = 1;i <= n + 1;++i){
cout << ans[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... |