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;
using pii = pair<int, int>;
void solve()
{
int n;
cin >> n;
vector<pii> a(n + 1);
for (int i = 0; i <= n; ++i)
cin >> a[i].first, a[i].second = i;
vector<int> b(n);
for (int &i : b)
cin >> i;
sort(b.begin(), b.end());
sort(a.begin(), a.end());
vector<int> ans(n + 1);
multiset<int> st;
for (int i = 1; i <= n; ++i)
st.emplace(max(0, a[i].first - b[i - 1]));
ans[a[0].second] = *prev(st.end());
for (int i = 1; i <= n; ++i)
{
st.erase(st.find(max(0, a[i].first - b[i - 1])));
st.emplace(max(0, a[i - 1].first - b[i - 1]));
ans[a[i].second] = *prev(st.end());
}
for (int i : ans)
cout << i << ' ';
cout << '\n';
}
/*
3
4 3 7 6
2 6 4
5
4 7 9 10 11 12
3 5 7 9 11
*/
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
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... |