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 ld long double
#define ar array
const int INF = 1e15;
const int MOD = 1e9+7;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin>>n;
vector<ar<int,2>> a(n+1);
vector<int> b(n);
for (int i = 0; i <= n; i++) {
cin>>a[i][0]; a[i][1] = i;
}
for (int &i : b) cin>>i;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int pf[n], sf[n];
pf[0] = a[0][0]-b[0];
for (int i = 1; i < n; i++) pf[i] = max(pf[i-1], a[i][0]-b[i]);
sf[n-1] = a[n][0]-b[n-1];
for (int i = n-2; i >= 0; --i) sf[i] = max(sf[i+1], a[i+1][0]-b[i]);
vector<int> ans(n+1);
ans[a[0][1]] = sf[0];
for (int i = 1; i < n; i++) {
ans[a[i][1]] = max(sf[i], pf[i-1]);
}
ans[a[n][1]] = pf[n-1];
for (int i : ans) cout<<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... |