Submission #762991

#TimeUsernameProblemLanguageResultExecution timeMemory
762991vjudge1Just Long Neckties (JOI20_ho_t1)C++14
100 / 100
75 ms6936 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 200005;
pair <int, int> a[N];
int b[N];
int diff[N], diff2[N], ans[N];
int st[4*N];
int n;

void build(int l, int r, int id){
    if (l == r){
        st[id] = diff[l];
        return;
    }
    int mid = (l+r)/2;
    build(l, mid, 2*id);
    build(mid+1, r, 2*id+1);
    st[id] = max(st[2*id], st[2*id+1]);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n+1; i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    for (int i = 1; i <= n; i++){
        cin >> b[i];
    }
    sort(a + 1, a + n + 2);
    sort(b + 1, b + n + 1);
    diff[1] = max(a[1].first - b[1], 0);
    diff2[n+1] = max(a[n+1].first - b[n], 0);
    for (int i = 2; i <= n; i++){
        diff[i] = max(diff[i-1], max(a[i].first - b[i], 0));
    }
    for (int i = n; i > 1; i--){
        diff2[i] = max(diff2[i+1], max(a[i].first - b[i-1], 0));
    }
    for (int i = 1; i <= n+1; i++){
        ans[a[i].second] = max(diff[i-1], diff2[i+1]);
    }
    for (int i = 1; i <= n+1; i++){
        cout << ans[i] << ' ';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...