이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int32_t main() {
int n;
cin >> n;
vector<pii> a(n+1); int id = 0;
vector<int> b(n), ans(n+1);
for(auto &x : a) cin >> x.first, x.second = id++;
for(int &x : b) cin >> x;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> pref(n+1), suf(n+1);
pref[0] = a[0].first - b[0];
suf[n] = a[n].first - b[n-1];
for(int i=1; i<n+1; i++) pref[i] = max({ pref[i-1], 0, a[i].first - b[i] });
for(int i=n-1; i>=1; i--) suf[i] = max({ suf[i+1], 0, a[i].first - b[i-1] });
for(int i=0; i<=n; i++) {
int res = 0;
if(i) res = pref[i-1];
if(i != n) res = max(res, suf[i+1]);
ans[a[i].second] = res;
}
for(int &x : ans) cout << x << " ";
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... |