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 <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vector<pair<LL, int> > A(N + 1);
vector<LL> B(N);
for (int i = 0; i <= N; i++) {
cin >> A[i].first;
A[i].second = i;
}
for (int i = 0; i < N; i++) {
cin >> B[i];
}
sort(A.begin(), A.end());
sort(B.begin(), B.end());
multiset<LL> vals;
for (int i = 0; i < N; i++) {
// After - Before;
vals.insert(max(A[i + 1].first - B[i], 0LL));
}
vector<LL> ans(N + 1);
for (int i = 0; i <= N; i++) {
if (i) {
vals.erase(vals.find(max(A[i].first - B[i - 1], 0LL)));
vals.insert(max(A[i - 1].first - B[i - 1], 0LL));
}
ans[A[i].second] = *vals.rbegin();
}
for (int i = 0; i <= N; i++) {
if (i) cout << ' ';
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... |