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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 4e5 + 10;
pair<int,int> a[maxn];
int b[maxn], pre[maxn], suf[maxn], ans[maxn];
int main(){
ios_base::sync_with_stdio(false);
int n;
cin >> n;
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);
for (int i = 1; i <= n; i++)
pre[i] = max(pre[i - 1], a[i].first - b[i]);
for (int i = n + 1; i >= 2; i--)
suf[i] = max(suf[i + 1], a[i].first - b[i - 1]);
for (int i = 1; i <= n+1; i++)
ans[a[i].second] = max(pre[i - 1], suf[i + 1]);
for (int i = 1; i <= n + 1; i++)
cout << ans[i] << " \n"[i==n+1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |