제출 #1130595

#제출 시각아이디문제언어결과실행 시간메모리
1130595lopkusJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
258 ms22612 KiB
#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n + 2);
    vector<int> b(n + 1);
    for(int i = 1; i <= n + 1; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    sort(b.begin() + 1, b.end());
    vector<int> ans(n + 2, 0);
    vector<pair<int,int>> A;
    A.push_back({-69, -69});
    for(int i = 1; i <= n + 1; i++) {
        A.push_back({a[i], i});
    }
    sort(A.begin() + 1, A.end());
    set<pair<int,int>> S;
    for(int i = 1; i <= n; i++) {
        S.insert({A[i + 1].first - b[i], i});
    }
    ans[A[1].second] = (*--S.end()).first;
    for(int i = 2; i <= n + 1; i++) {
        S.erase({A[i].first - b[i - 1], i - 1});
        S.insert({A[i - 1].first - b[i - 1], 69});
        ans[A[i].second] = (*--S.end()).first;
    }
    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...