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