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;
using ll = long long ;
int main() {
// freopen("moocast.in", "r", stdin);
// freopen("moocast.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
ll n, i, s;
cin >> n;
ll ans[n + 2];
pair < ll, ll > A[n + 2];
ll b[n + 2], aragshaa[n + 2], uragshaa[n + 2], Pre[n + 2], Suf[n + 2];
for (i = 1; i <= n + 1; i ++) {
cin >> A[i].first;
A[i].second = i;
}
for (i = 1; i <= n; i ++) {
cin >> b[i];
}
sort ( b + 1, b + n + 1);
sort ( A + 1, A + n + 2);
for (i = 1; i <= n; i ++) {
uragshaa[i] = max(0ll, A[i].first - b[i]);
aragshaa[i] = max(0ll, A[i + 1].first - b[i]);
}
Pre[0]= 0;
for (i = 1; i <=n; i ++) {
Pre[i]= max(Pre[i - 1] , uragshaa[i]);
}
Suf[n + 1] = 0;
for (i = n; i >= 1; i --) {
Suf[i] = max(Suf[i + 1] , aragshaa[i]);
}
for (i = 1; i <= n + 1; i ++) {
s = max(Suf[i] , Pre[i - 1]);
ans[A[i].second] = s;
}
for (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... |