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 ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
vector<pair<int, int>> a(n + 1);
for (int i = 0; i <= n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a.begin(), a.end());
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> b[i];
}
sort(b.begin(), b.end());
vector<int> pref(n), suff(n + 1);
for (int i = 0; i < n; i++) {
pref[i] = max(0, a[i].first - b[i]);
if (i > 0) smax(pref[i], pref[i - 1]);
}
for (int i = n; i >= 1; i--) {
suff[i] = max(0, a[i].first - b[i - 1]);
if (i < n) smax(suff[i], suff[i + 1]);
}
vector<int> ans(n + 1);
for (int i = 0; i <= n; i++) {
if (i > 0) ans[a[i].second] = pref[i - 1];
if (i < n) smax(ans[a[i].second], suff[i + 1]);
}
for (int i = 0; i <= n; i++) {
cout << ans[i] << sp;
}
cout << en;
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |