#include <bits/stdc++.h>
#define int long long
#define pb push_backk
#define fs first
#define sc second
using namespace std;
signed main() {
int n; cin >> n;
vector<pair<int, int>> a(n + 1);
vector<int> b(n);
multiset<int> t;
for(int i = 0; i < n + 1; i++) {
cin >> a[i].fs;
a[i].sc = i;
}
for(int i = 0; i < n; i++) cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> ans(n+1, 0);
for(int i = 0; i < n; i++) {
t.insert(a[i+1].fs - b[i]);
}
ans[a[0].sc] = max(0LL, *t.rbegin());
for(int i = 0; i < n; i++) {
t.erase(t.find(a[i+1].fs - b[i]));
t.insert(a[i].fs - b[i]);
ans[a[i+1].sc] = max(0LL, *t.rbegin());
}
for(auto 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... |