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 ll long long
#define X first
#define Y second
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define pb emplace_back
#define endl "\n"
const ll inf = 1e18;
const int N = 2e5 + 5;
typedef pair<int,int> ii;
ii a[N];
int b[N];
int Pre[N];
int Suf[N];
int ans[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
for(int i = 0 ; i <= n ; ++i) {
int x; cin >> x;
a[i].X = x;
a[i].Y = i;
}
for(int i = 1 ; i <= n ; ++i)
cin >> b[i];
sort(a ,a + 1 + n);
sort(b + 1,b + 1 + n);
for(int i = 1 ; i <= n ; ++i) Pre[i] = max(Pre[i - 1],a[i - 1].X - b[i]);
for(int i = n ; i >= 1 ; --i) Suf[i] = max(Suf[i + 1],a[i].X - b[i]);
for(int i = 0 ; i <= n ; ++i)
ans[a[i].Y] = max(Pre[i],Suf[i + 1]);
for(int i = 0 ; i <= n ; ++i)
cout << ans[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... |