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;
typedef pair<int, int> pii;
int main() {
int n;
cin >> n;
pii a[n+1];
for (int i = 0; i < n+1; i++) {
int x; cin >> x;
a[i] = {x, i};
}
sort(a, a + n+1);
int mappin[n+1];
for (int i = 0; i < n+1; i++) {
pii x = a[i];
mappin[x.second] = i;
}
cout << endl;
int b[n];
for (int i = 0; i < n; i++) cin >> b[i];
sort(b, b + n);
int direct[n];
for (int i = 0; i < n; i++) {
direct[i] = max(a[i].first - b[i], 0);
if (i > 0) {
direct[i] = max(direct[i], direct[i-1]);
}
}
int offset[n];
for (int i = 0; i < n; i++) {
offset[i] = max(a[i+1].first - b[i], 0);
}
for (int i = n - 2; i >= 0; i--) {
offset[i] = max(offset[i], offset[i+1]);
}
for (int i = 0; i < n+1; i++) {
int j = mappin[i];
if (j == 0) {
cout << offset[0] << " ";
} else if (j == n) {
cout << direct[n-1] << " ";
} else {
cout << max(direct[j-1], offset[j]) << " ";
}
}
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... |