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 int long long
using namespace std;
const int mx = 2e5+5;
int n;
pair<int,int> a[mx];
int b[mx];
int d[mx], rd[mx];
int ans[mx];
signed main() {
cin.tie(0);ios::sync_with_stdio(0);
cin >> 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,a+n+1);
sort(b,b+n);
multiset<int> st;
for (int i=0;i<n;i++) {
st.insert(max(a[i+1].first-b[i],0LL));
// cout << max(a[i+1].first-b[i],0LL) << "\n";
}
ans[a[0].second] = *--st.end();
// cout << a[0].second << " " << st.size() << "\n";
for (int i=0;i<n;i++) {
st.erase(st.find(max(a[i+1].first-b[i], 0LL)));
// cout << max(a[i+1].first-b[i], 0LL) << " " << max(a[i].first-b[i], 0LL) << "\n";
st.insert(max(a[i].first-b[i],0LL));
// cout << a[i].second << "owo\n";
ans[a[i+1].second] = *--st.end();
}
for (int i=0;i<=n;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... |