Submission #1221182

#TimeUsernameProblemLanguageResultExecution timeMemory
1221182takoshanavaJust Long Neckties (JOI20_ho_t1)C++20
1 / 100
2 ms332 KiB
#include <bits/stdc++.h>
#define int long long
#define pb push_backk
#define fs first
#define sc second
using namespace std;

signed main() {
    
    int n; cin >> n;
    vector<pair<int, int>> a(n + 1);
    vector<int> b(n);
    multiset<int> t;
    
    for(int i = 0; i < n + 1; i++) {
        cin >> a[i].fs;
        a[i].sc = i;
    }
    for(int i = 0; i < n; i++) cin >> b[i];

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

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

    for(int i = 0; i < n; i++) {
        t.insert(a[i+1].fs - b[i]);
    }

    ans[a[0].sc] = max(0LL, *t.rbegin());

    for(int i = 0; i < n; i++) {
        t.erase(a[i+1].fs - b[i]);
        t.insert(a[i].fs - b[i]);
        ans[a[i+1].sc] = max(0LL, *t.rbegin());
    }

    for(auto i : ans) cout << i << " ";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...