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>
#define fn(n) for(int i=1; i<=n; i++)
#define v first
#define s second
using namespace std;
using ll=long long;
int n;
pair<int, int> a[200002];
int c[200002];
int res[200002];
int f[200002];
int s[200002];
void nhap(){
cin >> n;
for(int i=1; i<=n+1; i++){
cin >> a[i].v;
a[i].s=i;
}
fn(n) cin >> c[i];
sort(a+1, a+n+2);
sort(c+1, c+n+1);
}
void solve(){
for(int i=1; i<=n; i++){
f[i]=max(f[i-1], max(a[i].v-c[i], 0));
}
for(int i=n; i>=1; i--){
s[i]=max(s[i+1], max(a[i+1].v-c[i], 0));
}
for(int i=1; i<=n+1; i++){
res[a[i].s]=max(f[i-1], s[i]);
}
for (int i=1; i<=n+1; i++) cout << res[i] << ' ';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
nhap();
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |