Submission #1117991

#TimeUsernameProblemLanguageResultExecution timeMemory
1117991heeyJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
84 ms15448 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long


signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<int> b(n);
    vector<pair<int,int>> a(n+1);
    for(int i = 0; i <= n; i++){
        int v; cin >> v;
        a[i] = {v, i};
    }
    for(int i = 0; i < n; i++) cin >> b[i];


    sort(b.begin(), b.end());
    sort(a.begin(), a.end());

    vector<int> p(n+1, 0), s(n+1, 0);

    for(int i = 1; i <= n; i++){
        p[i] = max(p[i-1], max(a[i-1].first -  b[i-1], 0ll));
    }

    for(int i = n-1; i >= 0; i--) s[i] = max(s[i+1], max(a[i+1].first - b[i], 0ll));

    /*cout << "prefix\n";
    for(int i = 0; i <= n; i++) cout << p[i] << ' ';
    cout << "\nsuffix\n";
    for(int i = 0; i <= n; i++) cout << s[i] << ' ';
    cout << '\n';*/


    vector<int> ans(n+1);
    for(int i = 0; i <= n; i++) ans[a[i].second] = max(p[i], s[i]);

    for(int i = 0; i <= n; i++) cout << ans[i] << ' ';

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