제출 #349919

#제출 시각아이디문제언어결과실행 시간메모리
349919shivensinha4Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
327 ms21996 KiB
#include "bits/stdc++.h"
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'


int main() {
#ifdef mlocal
    freopen("test.in", "r", stdin);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    vector<ll> b(n);
    vector<pair<ll, int>> a(n+1);
    for_(i, 0, n+1) {
        cin >> a[i].first;
        a[i].second = i;
    }

    for_(i, 0, n) cin >> b[i];
    sort(a.begin(), a.end()); sort(b.begin(), b.end());

    multiset<ll> s;
    vector<ll> ans(n+1);
//    for_(i, 0, n+1) cout << a[i].first << " " << a[i].second << endl;
    for_(i, 1, n+1) {
        s.insert(a[i].first-b[i-1]);
    }

//    for (auto j: s) cout << j << " ";
//    cout << endl;
    ans[a[0].second] = *s.rbegin();
    for_(i, 1,n+1) {
        s.erase(s.find(a[i].first-b[i-1]));
        s.insert(a[i-1].first-b[i-1]);
//        for (auto j: s) cout << j << " ";
//        cout << endl;
        ans[a[i].second] = *s.rbegin();
    }

    for_(i, 0, n+1) cout << max(0LL, ans[i]) << " ";
    cout << endl;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...