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 sp << " " <<
#define nl << "\n"
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
array<int, 2> a[n+1];
int b[n];
for(int i=0; i<=n; ++i) cin >> a[i][0], a[i][1] = i;
for(int &i : b) cin >> i;
sort(b, b+n);
sort(a, a+n+1);
int pre[n], suf[n+1];
pre[0] = max(a[0][0] - b[0], 0LL);
suf[n] = max(a[n][0] - b[n-1], 0LL);
for(int i=1; i<n; ++i){
pre[i] = max(pre[i-1], max(a[i][0] - b[i], 0LL));
suf[n-i] = max(suf[n-i+1], max(a[n-i][0] - b[n-i-1], 0LL));
}
int ans[n+1];
for(int i=0; i<=n; ++i){
int curr = 0;
if(i) curr = max(curr, pre[i-1]);
if(i<n) curr = max(curr, suf[i+1]);
ans[a[i][1]] = curr;
}
for(int i : ans) cout << i << ' ';
cout nl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |