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;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
typedef vector<pl> vpl;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
ll n;
cin >> n;
vpl w;
vl x;
for(int i=0;i<n+1;i++) {
ll t;
cin >> t;
w.push_back({t,i});
}
sort(w.begin(),w.end());
for(int i=0;i<n;i++) {
ll t;
cin >> t;
x.push_back(t);
}
sort(x.begin(),x.end());
vl res(n+1,-1);
ll rr = 0;
for(int i=0;i<n;i++) {
rr = max(rr,w[i].first-x[i]);
res[i+1] = max(res[i+1],rr);
}
rr = 0;
for(int i=n-1;i>=0;i--) {
rr = max(rr,w[i+1].first-x[i]);
res[i] = max(res[i],rr);
}
vl ans(n+1);
for(int i=0;i<=n;i++) {
ans[w[i].second] = res[i];
}
for(int i=0;i<=n;i++) {
if(i > 0) {cout << " ";}
cout << ans[i];
}
cout << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |