제출 #1162988

#제출 시각아이디문제언어결과실행 시간메모리
1162988tw20000807Just Long Neckties (JOI20_ho_t1)C++20
100 / 100
150 ms17836 KiB
#include<bits/stdc++.h>
#define int long long
#define all(v) v.begin(), v.end()
#define SZ(x) (int)x.size()
#define pii pair<int, int>
#define X first
#define Y second

using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;//    998244353;
const int llmx = 1e18;

void sol(){
    int n; cin >> n;
    vector< pii > v(n + 1);
    for(int i = 0; i <= n; ++i){
        cin >> v[i].X;
        v[i].Y = i;
    }
    vector< int > b(n), ans(n + 1);
    for(auto &i : b) cin >> i;
    sort(all(v));
    sort(all(b));
    multiset< int > s;
    for(int i = 0; i < n; ++i){
        s.insert(v[i].X - b[i]);
    }
    ans[v.back().Y] = max(0LL, *prev(s.end()));
    for(int i = n - 1; i >= 0; --i){
        s.erase(v[i].X - b[i]);
        s.insert(v[i + 1].X - b[i]);
        ans[v[i].Y] = max(0LL, *prev(s.end()));
    }
    for(int i = 0; i <= n; ++i) cout << ans[i] << " \n"[i == n];
}
/*
3
4 3 7 6
2 6 4

// 2 2 1 1

*/
signed main(){
    ios::sync_with_stdio(0), cin.tie(0), cerr.tie(0);
    int t = 1; //cin >> t;
    while(t--) sol();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...