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 pii pair<long long, long long>
#define fr first
#define se second
int32_t main() {
//freopen("in", "r", stdin);
int n;
cin >> n;
vector<pii> a(n + 2);
vector<int> b(n + 1);
for (int i = 1; i <= (n + 1); i++) {
cin >> a[i].fr;
a[i].se = i;
}
for (int i = 1; i <= n; i++) cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> pf(n + 5), sf(n + 5);
for (int i = 1; i <= n; i++) {
int c = max(a[i].fr - b[i], 0LL);
pf[i] = max(pf[i - 1], c);
}
for (int i = n + 1; i >= 2; i--) {
int c = max(a[i].fr - b[i - 1], 0LL);
sf[i] = max(sf[i + 1], c);
}
vector<int> ans(n + 2);
for (int i = 1; i <= (n + 1); i++) {
ans[a[i].se] = max(pf[i - 1], sf[i + 1]);
}
for (int i = 1; i <= (n + 1); i++) cout << ans[i] << " ";
cout << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |