이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 5e5+5, oo = 1e18+10;
ll a[N], b[N], ans[N], p[N], s[N], n;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for(int i = 1; i <= n+1; ++i) {
cin >> a[i];
}
for(int i = 1; i <= n; ++i) {
cin >> b[i];
}
vector<int> ids(n+1);
iota(ids.begin(), ids.end(), 1);
sort(ids.begin(), ids.end(), [&](int x, int y) {
return a[x] < a[y];
});
sort(b+1, b+n+1);
for(int i = 1; i <= n+1; ++i) {
p[i] = max(p[i-1], a[ids[i - 1]] - b[i]);
}
for(int i = n+1; i >= 1; --i) {
s[i] = max(s[i+1], a[ids[i - 1]] - b[i - 1]);
}
for(int i = 1; i <= n+1; ++i) {
ans[ids[i - 1]] = max(p[i-1], s[i+1]);
}
for(int i = 1; i <= n+1; ++i) {
cout << ans[i] << ' ';
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |