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 di pair<int, int>
int nbTypes;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> nbTypes;
vector<di> a(nbTypes + 1);
for (int iT = 0; iT <= nbTypes; iT ++) {
int x;
cin >> x;
a[iT] = { x, iT };
}
vector<int> b(nbTypes);
for (int jT = 0; jT < nbTypes; jT ++)
cin >> b[jT];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> c(nbTypes + 1);
vector<int> d(nbTypes + 1);
for (int iT = 0; iT < nbTypes; iT ++) {
c[iT] = a[iT].first - b[iT];
d[iT + 1] = a[iT + 1].first - b[iT];
}
for (int iT = 1; iT <= nbTypes; iT ++)
c[iT] = max(c[iT], c[iT - 1]);
for (int jT = nbTypes - 1; jT >= 0; jT --)
d[jT] = max(d[jT + 1], d[jT]);
vector<int> res (nbTypes + 1);
for (int i = 0; i <= nbTypes; i ++) {
int mu = i == 0 ? 0 : c[i - 1];
int nu = i == nbTypes ? 0 : d[i + 1];
res[a[i].second] = max(mu, nu);
}
for (int u : res)
cout << u << " ";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |