이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
vector<pair<int, int>> a(n + 1);
for (int i = 0; i <= n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a.begin(), a.end());
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> b[i];
}
sort(b.begin(), b.end());
vector<int> pref(n), suff(n + 1);
for (int i = 0; i < n; i++) {
pref[i] = max(0, a[i].first - b[i]);
if (i > 0) smax(pref[i], pref[i - 1]);
}
for (int i = n; i >= 1; i--) {
suff[i] = max(0, a[i].first - b[i - 1]);
if (i < n) smax(suff[i], suff[i + 1]);
}
vector<int> ans(n + 1);
for (int i = 0; i <= n; i++) {
if (i > 0) ans[a[i].second] = pref[i - 1];
if (i < n) ans[a[i].second] = suff[i + 1];
}
for (int i = 0; i <= n; i++) {
cout << ans[i] << sp;
}
cout << en;
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... |