Submission #1117271

#TimeUsernameProblemLanguageResultExecution timeMemory
1117271wellthen_Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
164 ms10824 KiB
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> availableties(n+1);
    for(int i = 0; i<=n; i++){
        cin >> availableties[i].first;
        availableties[i].second = i;
    }
    vector<int> initialties(n);
    for(int i = 0; i<n; i++){
        cin >> initialties[i];
    }
    sort(initialties.begin(), initialties.end());
    sort(availableties.begin(), availableties.end());
    vector<int> ans(n+1);
    vector<int> pref(n+1);
    for(int i = 1; i<=n; i++){
        pref[i] = max(pref[i-1], max(0, availableties[i-1].first-initialties[i-1]));
    }
    vector<int> suff(n+1);
    for(int i = n-1; i>=0; i--){
        suff[i] = max(suff[i+1], max(0, availableties[i+1].first-initialties[i]));
    }
    for(int i = 0; i<n+1; i++){
        // assign the ith tie to the ceo
        ans[availableties[i].second] = max(pref[i], suff[i]);
    }
    for(int i = 0; i<=n; i++){
        cout << ans[i] << " ";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...