Submission #1297525

#TimeUsernameProblemLanguageResultExecution timeMemory
1297525hynmjJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
196 ms11636 KiB

#include <bits/stdc++.h>
#define int long long
using namespace std;
const long long N = 2e5 + 5;
int p[N], s[N], b[N], ans[N];

void solve()
{
    int n;
    cin >> n;
    vector<pair<int, int>> a(n + 2);
    for (int i = 0; i <= n; i++)
    {
        cin >> a[i + 1].first;
        a[i + 1].second = i + 1;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i + 1];
    }
    sort(a.begin() + 1, a.end());
    sort(b + 1, b + n + 1);
    for (int i = 0; i < n; i++)
    {
        p[i + 1] = max(p[i], a[i + 1].first - b[i + 1]);
    }
    for (int i = n; i >= 1; i--)
    {
        s[i] = max(s[i + 1], a[i + 1].first - b[i]);
    }
    for (int i = 0; i < n + 1; i++)
    {
        ans[a[i + 1].second] = max(p[i], s[i + 1]);
    }
    for (int i = 1; i <= n+1; i++)
    {
        cout << ans[i] << endl;
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    // cin >> t;/
    for (int i = 1; i <= t; i++)
    {
        // cout << "Case #" << i << ':' << ' ';
        solve();
        cout << endl;
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...