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;
#define int long long
#define fi first
#define se second
const int maxn = 1e6+5;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
pair<int, int> a[maxn];
for (int i = 1; i <= n+1; i++){
cin >> a[i].fi;
a[i].se = i;
}
int b[maxn];
for (int i = 1; i <= n; i++) cin >> b[i];
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
int prefix[maxn], suffix[maxn];
for (int i = 1; i <= n; i++) prefix[i] = max(prefix[i-1], a[i].fi - b[i]);
for (int i = n; i >= 1; i--) suffix[i] = max(suffix[i+1], a[i+1].fi - b[i]);
int kq[maxn];
for (int i = 1; i <= n+1; i++) kq[a[i].se] = max(prefix[i-1], suffix[i]);
for (int i = 1; i <= n+1; i++) cout << kq[i] << ' ';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |