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 for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'
int main() {
#ifdef mlocal
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<ll> b(n);
vector<pair<ll, int>> a(n+1);
for_(i, 0, n+1) {
cin >> a[i].first;
a[i].second = i;
}
for_(i, 0, n) cin >> b[i];
sort(a.begin(), a.end()); sort(b.begin(), b.end());
multiset<ll> s;
vector<ll> ans(n+1);
// for_(i, 0, n+1) cout << a[i].first << " " << a[i].second << endl;
for_(i, 1, n+1) {
s.insert(a[i].first-b[i-1]);
}
// for (auto j: s) cout << j << " ";
// cout << endl;
ans[a[0].second] = *s.rbegin();
for_(i, 1,n+1) {
s.erase(s.find(a[i].first-b[i-1]));
s.insert(a[i-1].first-b[i-1]);
// for (auto j: s) cout << j << " ";
// cout << endl;
ans[a[i].second] = *s.rbegin();
}
for_(i, 0, n+1) cout << max(0LL, ans[i]) << " ";
cout << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |