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 ll long long
#define ar array
const int mxN = 2e5+10;
int n, b[mxN];
ar<int, 2> a[mxN];
int dif1[mxN], dif2[mxN], ans[mxN];
int main(){
std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
cin >> n;
for(int i = 0; i<n+1; ++i){
cin >> a[i][0], a[i][1] = i;
}
for(int i = 0; i<n; ++i){
cin >> b[i];
}
sort(a, a+n+1);
sort(b, b+n);
for(int i = 0; i<n; ++i){
dif1[i] = max(a[i+1][0]-b[i], 0);
dif2[i+1] = max(a[i][0]-b[i], 0);
}
for(int i = n-1; i>=0; --i){
dif1[i] = max(dif1[i], dif1[i+1]);
}
for(int i = 1; i<=n; ++i){
dif2[i] = max(dif2[i], dif2[i-1]);
}
for(int i = 0; i<=n; ++i){
ans[a[i][1]] = max(dif1[i], dif2[i]);
}
for(int i = 0; i<=n; ++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... |