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); cout.tie(0);
int N; cin >> N;
vector<pair<int,int>> arr(N+1);
for(int i = 0;i<=N;++i){
cin >> arr[i].first;
arr[i].second = i;
}
sort(arr.begin(),arr.end());
vector<int> brr(N);
for(int i = 0;i<N;++i) cin >> brr[i];
sort(brr.begin(),brr.end());
vector<int> pref(N),suf(N);
for(int i = 0;i<N;++i){
if(i == 0){
pref[i] = max(arr[i].first-brr[i],0);
}
else{
pref[i] = max(max(arr[i].first-brr[i],0),pref[i-1]);
}
}
for(int i = N-1;i>=0;--i){
if(i == N-1){
suf[i] = max(arr[i+1].first-brr[i],0);
}
else{
suf[i] = max(max(arr[i+1].first-brr[i],0),suf[i+1]);
}
}
vector<int> ans(N+1);
for(int i = 0;i<=N;++i){
if(i == 0) ans[arr[i].second] = suf[i];
else if(i == N) ans[arr[i].second] = pref[N-1];
else{
ans[arr[i].second] = max(suf[i],pref[i-1]);
}
}
for(int i = 0;i<=N;++i) cout << ans[i] << " ";
cout << "\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... |