Submission #1297341

#TimeUsernameProblemLanguageResultExecution timeMemory
1297341baotoan655Just Long Neckties (JOI20_ho_t1)C++20
100 / 100
65 ms7140 KiB
#include <bits/stdc++.h>
#define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
using namespace std;

const int N = 2e5 + 5;
int B[N];
pair<int, int> A[N];

int C[N], D[N], ans[N];
int n;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

//    file("A") else file("task");

    cin >> n;
    for(int i = 1; i <= n + 1; ++i) {
        cin >> A[i].first;
        A[i].second = i;
    }
    for(int i = 1; i <= n; ++i) cin >> B[i];
    sort(A + 1, A + n + 2);
    sort(B + 1, B + n + 1);

    for(int i = 1; i <= n; i++) C[i] = max(C[i - 1], A[i].first - B[i]);
    for(int i = n; i >= 1; i--) D[i] = max(D[i + 1], A[i + 1].first - B[i]);

    for(int i = 1; i <= n + 1; i++) ans[A[i].second] = max(C[i - 1], D[i]);
    for(int i = 1; i <= n + 1; i++) cout << ans[i] << ' ';
    return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...