This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n; cin >> n;
pair<int, int> a[n + 2]{};
int b[n + 1]{};
for (int i = 1; i <= n + 1; i++){
cin >> a[i].first;
a[i].second = i;
}
for (int i = 1; i <= n; i++){
cin >> b[i];
}
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
int pref[n + 1]{};
for (int i = 1; i <= n; i++){
pref[i] = max(pref[i - 1], a[i].first - b[i]);
}
int suff[n + 3]{};
for (int i = n + 1; i > 1; i--){
suff[i] = max(suff[i + 1], a[i].first - b[i - 1]);
}
int ans[n + 2]{};
for (int i = 1; i <= n + 1; i++){
ans[a[i].second] = max(pref[i - 1], suff[i + 1]);
}
for (int i = 1; i <= n + 1; i++){
cout << ans[i] << " \n"[i == n + 1];
}
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... |