Submission #1051278

#TimeUsernameProblemLanguageResultExecution timeMemory
1051278fryingducJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
60 ms10840 KiB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 2e5 + 5;
int n, b[maxn];

pair<int, int> a[maxn];

int ans[maxn];

int pref[maxn], suf[maxn];

void solve() {
    cin >> n;
    for(int i = 1; i <= n + 1; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 2);
    for(int i = 1; i <= n; ++i) {
        cin >> b[i];
    }
    sort(b + 1, b + n + 1);
    for(int i = 1; i <= n; ++i) {
        pref[i] = max(pref[i - 1], a[i].first - b[i]);
    }
    for(int i = n; i; --i) {
        suf[i] = max(suf[i + 1], a[i + 1].first - b[i]);
    }
    
    for(int i = 1; i <= n + 1; ++i) {
        ans[a[i].second] = max(pref[i - 1], suf[i]);
    }
    
    for(int i = 1; i <= n + 1; ++i) {
        cout << ans[i] << " ";
    }
}
signed main() {
    ios_base::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...