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 int long long
#define st first
#define nd second
const int maxn = 2e5 + 5;
int ans[maxn], b[maxn], st[maxn * 4], n;
pair<int, int> a[maxn];
void build(int id, int l, int r){
if(l == r){
st[id] = max(a[l + 1].st - b[l], 0ll);
return;
}
int m = (l + r) >> 1;
build(id * 2, l, m);
build(id * 2 + 1, m + 1, r);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
void update(int id, int l, int r, int pos){
if(l > pos || r < pos)
return;
if(l == r){
st[id] = max(a[l].st - b[l], 0ll);
return;
}
int m = (l + r) >> 1;
update(id * 2, l, m, pos);
update(id * 2 + 1, m + 1, r, pos);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i = 1 ; i <= n + 1 ; i++){
cin >> a[i].st;
a[i].nd = i;
}
for(int i = 1 ; i <= n ; i++)
cin >> b[i];
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
build(1, 1, n);
ans[a[1].nd] = st[1];
for(int i = 2 ; i <= n + 1 ; i++){
update(1, 1, n, i - 1);
ans[a[i].nd] = st[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... |