Submission #210783

#TimeUsernameProblemLanguageResultExecution timeMemory
210783aryan12Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
131 ms10104 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        long long n;
        cin >> n;
        long long a[n + 1];
        vector<pair<long long, long long> >b(n + 2); //wearing and index
        for(long long i = 0; i <= n; i++) {
            cin >> b[i].first; //to wear
            b[i].second = i;
        }
        for(long long i = 1; i <= n; i++) {
            cin >> a[i]; //already wearing
        }
        sort(a + 1, a + 1 + n);
        a[0] = -1;
        sort(b.begin(), b.end() - 1);
        /*for(long long i = 0; i <= n; i++) {
            cout << a[i] << " " << b[i].first << endl;
        }*/
        long long c[n + 1], ans = 0, d = 0;
        long long suf[n + 1];
        suf[n] = b[n].first - a[n];
        for(long long i = n - 1; i > 0; i--) {
            suf[i] = max(suf[i + 1], b[i].first - a[i]);
        }
        for(long long i = 0; i <= n; i++) {
            if(i != 0) {
                d = max(d, b[i - 1].first - a[i]);
            }
            //managers necklace;
            if(i != n)
                ans = max(d, suf[i + 1]);
            else
                ans = d;
            c[b[i].second] = ans;
        }
        for(long long i = 0; i <= n; i++) {
            cout << c[i] << " ";
        }
        cout << endl;
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...