이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
const int N = 2e5 + 5;
int n, a[N], b[N];
int p[N], o[N], pf[N], sf[N];
int main() {
cin.tie(0)->sync_with_stdio(0), cin.exceptions(cin.failbit);
cin >> n;
for (int i = 0; i <= n; i++) cin >> a[i], p[i] = i;
for (int i = 0; i < n; i++) cin >> b[i];
sort(p, p + n + 1, [ & ](int i, int j) {
return a[i] < a[j];
});
for (int i = 0; i <= n; i++) o[p[i]] = i;
sort(b, b + n);
for (int i = 0; i < n; i++) pf[i] = max(i > 0 ? pf[i - 1] : 0, max(a[p[i]] - b[i], 0));
for (int i = n; i >= 1; i--) sf[i] = max(i < n ? sf[i + 1] : 0, max(a[p[i]] - b[i - 1], 0));
for (int i = 0; i <= n; i++) {
int j = o[i];
cout << max(j > 0 ? pf[j - 1] : 0, j < n ? sf[j + 1] : 0) << " \n" [i == 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... |