This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//I wrote this code 4 u <3
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
signed main(int32_t argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
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 + 2, 0), suf(n + 2, 0);
for (int i = 0; i < n; ++i) {
pref[i + 1] = max(pref[i], a[i].first - b[i]);
}
for (int i = n - 1; i > -1; --i) {
suf[i] = max(suf[i + 1], a[i + 1].first - b[i]);
}
vector<int> ans(n + 1);
for (int i = 0; i <= n; ++i) {
ans[a[i].second] = max(pref[i], suf[i]);
}
for (auto x : ans) {
cout << x << ' ';
}
}
/*
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |