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;
const int N = 200005;
pair <int, int> a[N];
int b[N];
int diff[N], diff2[N], ans[N];
int st[4*N];
int n;
void build(int l, int r, int id){
if (l == r){
st[id] = diff[l];
return;
}
int mid = (l+r)/2;
build(l, mid, 2*id);
build(mid+1, r, 2*id+1);
st[id] = max(st[2*id], st[2*id+1]);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n+1; i++){
cin >> a[i].first;
a[i].second = i;
}
for (int i = 1; i <= n; i++){
cin >> b[i];
}
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
diff[1] = max(a[1].first - b[1], 0);
diff2[n+1] = max(a[n+1].first - b[n], 0);
for (int i = 2; i <= n; i++){
diff[i] = max(diff[i-1], max(a[i].first - b[i], 0));
}
for (int i = n; i > 1; i--){
diff2[i] = max(diff2[i+1], max(a[i].first - b[i-1], 0));
}
for (int i = 1; i <= n+1; i++){
ans[a[i].second] = max(diff[i-1], diff2[i+1]);
}
for (int i = 1; i <= n+1; 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... |