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;
int main() {
int n;
cin >> n;
vector <pair <int, int>> a(n+1);
vector <int> b(n);
for (int i = 0; i < n+1; i++) {
cin >> a[i].first;
a[i].second = i;
}
for (int i = 0; i < n; i++)
cin >> b[i];
sort(b.begin(), b.end());
vector <pair <int, int>> a2 = a;
sort(a2.begin(), a2.end());
multiset <int> d;
for (int i = 1; i < n+1; i++) {
d.insert(max(0, a2[i].first - b[i-1]));
}
vector <int> ans(n+1);
ans[a2[0].second] = *d.rbegin();
for (int i = 0; i < n; i++) {
d.insert(max(0, a2[i].first - b[i]));
d.erase(d.find(max(0, a2[i+1].first - b[i])));
ans[a2[i+1].second] = *d.rbegin();
}
for (int i = 0; i < n+1; i++)
cout << ans[i] << ' ';
cout << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |