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>
#define F first
#define S second
#define all(a) begin(a), end(a)
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
void solve() {
int n;
cin >> n;
vector<int> a(n+1);
vector<int> b(n);
vector<int> ind(n+1);
iota(all(ind), 0);
for (auto &it : a) cin >> it;
for (auto &it : b) cin >> it;
sort(all(b));
sort(all(ind), [&](int i, int j) {
return a[i] < a[j];
});
vector<int> ans(n+1);
multiset<int, greater<>> s;
s.insert(0);
for (int i = 0; i < n; ++i) {
s.insert(a[ind[i]] - b[i]);
}
ans[ind[n]] = *s.begin();
for (int i = n - 1; i >= 0; --i) {
s.erase(s.find(a[ind[i]] - b[i]));
s.insert(a[ind[i+1]] - b[i]);
ans[ind[i]] = *s.begin();
}
for (auto a : ans) cout << a << ' ';
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
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... |