제출 #762944

#제출 시각아이디문제언어결과실행 시간메모리
762944vjudge1Just Long Neckties (JOI20_ho_t1)C++17
0 / 100
0 ms340 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define st first
#define nd second
const int maxn = 2e5 + 5;
int ans[maxn], a[maxn], b[maxn], st[maxn * 4], n;
void build(int id, int l, int r){
    if(l == r){
        st[id] = max(a[l + 1] - b[l], 0ll);
        return;
    }
    int m = (l + r) >> 1;
    build(id * 2, l, m);
    build(id * 2 + 1, m + 1, r);
    st[id] = max(st[id * 2], st[id * 2 + 1]);
}

void update(int id, int l, int r, int pos){
    if(l > pos || r < pos)
        return;
    if(l == r){
        st[id] = max(a[l] - b[l], 0ll);
        return;
    }
    int m = (l + r) >> 1;
    update(id * 2, l, m, pos);
    update(id * 2 + 1, m + 1, r, pos);
    st[id] = max(st[id * 2], st[id * 2 + 1]);
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i = 1 ; i <= n + 1 ; i++)
        cin >> a[i];
    for(int i = 1 ; i <= n ; i++)
        cin >> b[i];
    sort(a + 1, a + n + 2);
    sort(b + 1, b + n + 1);
    build(1, 1, n);
    ans[1] = st[1];
    for(int i = 2 ; i <= n + 1 ; i++){
        update(1, 1, n, i - 1);
        ans[i] = st[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...