이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n + 1), b(n), I(n + 1), ans(n + 1), dL(n), dR(n);
cin >> a >> b;
iota(I.begin(), I.end(), 0);
sort(I.begin(), I.end(), [&](int i, int j) {
return a[i] < a[j];
});
sort(b.begin(), b.end());
for(int k = 0; k < n; k++) {
dL[k] = max(a[I[k]] - b[k], 0);
dR[k] = max(a[I[k + 1]] - b[k], 0);
}
partial_sum(dL.begin(), dL.end(), dL.begin(), [](int x, int y) { return max(x, y); });
partial_sum(dR.rbegin(), dR.rend(), dR.rbegin(), [](int x, int y) { return max(x, y); });
for(int k = 0; k <= n; k++) {
ans[I[k]] = max(k ? dL[k - 1] : 0, k < n ? dR[k] : 0);
}
for(int i = 0; i <= n; i++) {
cout << ans[i] << " ";
}
cout << endl;
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... |