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;
#define finish(x) return cout << x << endl, 0
#define ll long long
int n;
vector <pair <int, int> > a;
vector <int> b;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
a.resize(n + 1);
for(int i = 0 ; i < n + 1 ; i++){
cin >> a[i].first;
a[i].second = i;
}
b.resize(n);
for(auto &i : b) cin >> i;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector <int> pref(n), suff(n);
for(int i = 0 ; i < n ; i++){
if(i > 0) pref[i] = pref[i - 1];
pref[i] = max(pref[i], a[i].first - b[i]);
}
for(int i = n - 1 ; i >= 0 ; i--){
if(i < n - 1) suff[i] = suff[i + 1];
suff[i] = max(suff[i], a[i + 1].first - b[i]);
}
vector <int> ans(n + 1);
for(int i = 0 ; i < n + 1 ; i++){
ans[a[i].second] = max((i > 0 ? pref[i - 1] : 0), (i < n ? suff[i] : 0));
}
for(auto &i : ans) cout << i << " ";
cout << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |