Submission #1325995

#TimeUsernameProblemLanguageResultExecution timeMemory
1325995AgageldiJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
72 ms13180 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define N 500005
#define X first
#define Y second

const int inf = 1e18;

int tc = 1, n, suf[N], pref[N], ans[N];
pair<int,int> a[N], b[N];

int32_t main() {
    ios::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n + 1; i++) {
        cin >> a[i].X;
        a[i].Y = i;
    }
    for(int i = 1; i <= n; i++) {
        cin >> b[i].X;
        b[i].Y = i;
    }
    sort(a + 1, a + n + 2);
    sort(b + 1, b + n + 1);
    for(int i = n; i >= 1; i--) {
        suf[i] = max(suf[i + 1], max(0ll, a[i + 1].X - b[i].X));
    }
    for(int i = 1; i <= n + 1; i++) {
        pref[i] = max(pref[i - 1], max(0ll, a[i].X - b[i].X));
        ans[a[i].Y] = max(pref[i - 1], suf[i]);
    }
    for(int i = 1; i <= n + 1; i++) {
        cout << ans[i] << " ";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...