Submission #1358565

#TimeUsernameProblemLanguageResultExecution timeMemory
1358565kismisJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
110 ms8448 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vt vector 
#define pb push_back
#define pob pop_back
#define endl '\n'
#define fi first
#define se second

signed main(){
    int n;
    cin >> n;
    vt<pair<int , int>> a(n+1);
    vt<int>b(n);
    for(int i=0 ; i<=n ; i++){
        cin >> a[i].fi;
        a[i].se = i;
    }
    vt<int> out(n+1);
    for(int i=0 ; i<n ; i++)
    cin >> b[i];
    sort(a.begin() , a.end());
    sort(b.begin() , b.end());
    int ans = LLONG_MIN;
    for(int i=0 ; i<n ; i++){
        int temp = max(0LL , a[i].fi-b[i]);
        ans = max(temp , ans);
    }
    out[a[n].se]=ans;
    int nc = a[n].fi;
    for(int i=n-1 ; i>=0 ; i--){
       int temp = max(0LL , nc - b[i]);
       ans = max(temp , ans);
       out[a[i].se] = ans;
       nc = a[i].fi;
    }
    for(int i=0 ; i<=n ; i++)
    cout << out[i] << " ";
    cout << endl;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...