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 <iostream>
#include <algorithm>
using namespace std;
int n;
pair<int, int> arr[200005];
int brr[200005];
int suffix[200005];
int prefix[200005];
int answer[200005];
int main(){
cin >> n;
for(int i = 1;i<=n+1;i++){
cin >> arr[i].first;
arr[i].second = i;
}
for(int i = 1;i<=n;i++){
cin >> brr[i];
}
sort(arr+1, arr+n+2);
sort(brr+1, brr+n+1);
int maxi =0;
for(int i = 1; i <= n;i++){
maxi = max(maxi, arr[i].first-brr[i]);
prefix[i] = maxi;
}
maxi = 0;
for(int i = n; i >=1;i--){
maxi = max(maxi, arr[i+1].first-brr[i]);
suffix[i] = maxi;
}
for(int i =1 ; i <=n+1;i++){
answer[arr[i].second] = max(prefix[i-1], suffix[i]);
}
for(int i = 1; i<=n+1;i++){
cout << answer[i] << " ";
}
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... |