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;
const int N = 200005;
int n, a[N], b[N], pr[N], su[N], ans[N];
vector<int> ind;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n + 1; i++) {
cin >> a[i];
ind.push_back(i);
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
sort(ind.begin(), ind.end(), [](const int &u, const int &v) {
return a[u] < a[v];
});
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
for (int i = 1; i <= n; i++) {
pr[i] = max(pr[i - 1], a[i] - b[i]);
}
for (int i = n; i >= 1; i--) {
su[i] = max(su[i + 1], a[i + 1] - b[i]);
}
for (int i = 0; i <= n; i++) {
ans[ind[i]] = max(pr[i], su[i + 1]);
}
for (int 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... |