제출 #435920

#제출 시각아이디문제언어결과실행 시간메모리
435920dariascJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
277 ms10800 KiB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

int main() {
    int n;
    cin >> n;
    pii a[n+1];
    for (int i = 0; i < n+1; i++) {
        int x; cin >> x;
        a[i] = {x, i};
    }
    sort(a, a + n+1);
    int mappin[n+1];
    for (int i = 0; i < n+1; i++) {
        pii x = a[i];
        mappin[x.second] = i;
    }
    cout << endl;

    int b[n];
    for (int i = 0; i < n; i++) cin >> b[i];
    sort(b, b + n);

    int direct[n];
    for (int i = 0; i < n; i++) {
        direct[i] = max(a[i].first - b[i], 0);
        if (i > 0) {
            direct[i] = max(direct[i], direct[i-1]);
        }
    }
    int offset[n];
    for (int i = 0; i < n; i++) {
        offset[i] = max(a[i+1].first - b[i], 0);
    }
    for (int i = n - 2; i >= 0; i--) {
        offset[i] = max(offset[i], offset[i+1]);
    }

    for (int i = 0; i < n+1; i++) {
        int j = mappin[i];
        if (j == 0) {
            cout << offset[0] << " ";
        } else if (j == n) {
            cout << direct[n-1] << " ";
        } else {
            cout << max(direct[j-1], offset[j]) << " ";
        }
    }

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