#include <bits//stdc++.h>
using namespace std;
#define ll long long
#define st short
#define iloop(m, h) for (auto i = m; i < h; i++)
#define jloop(m, h) for (auto j = m; j < h; j++)
#define kloop(m, h) for (auto k = m; k < h; k++)
#define getchar_unlocked _getchar_nolock
#define pll pair<ll,ll>
#define vll vector<ll>
#define qll queue<ll>
#define dll deque<ll>
#define pqll priority_queue<ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, m;
cin >> n;
pll a[n+1];
ll f[n+1], c[n+1], memo[n][2];
iloop(0, n+1) {cin >> a[i].first; a[i].second = i;}
iloop(0, n) cin >> c[i];
sort(a, a+n+1);
sort(c, c+n);
iloop(0, n) {
memo[i][0] = a[i].first - c[i];
memo[i+1][1] = a[i+1].first - c[i];
if (i != 0) {memo[i][0] = max(memo[i][0], memo[i-1][0]);}
}
iloop(1, n) {
memo[n-1-i][1] = max(memo[n-1-i][1], memo[n-i][1]);
}
iloop(0, n+1) {
m = 0;
if (i != 0) m = max(m, memo[i-1][0]);
if (i != n) m = max(m, memo[i+1][1]);
f[a[i].second] = m;
}
iloop(0, n+1) cout << f[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... |