Submission #924501

#TimeUsernameProblemLanguageResultExecution timeMemory
924501qwe1rt1yuiop1Just Long Neckties (JOI20_ho_t1)C++14
100 / 100
208 ms18756 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...