Submission #762912

#TimeUsernameProblemLanguageResultExecution timeMemory
762912huutuanJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
78 ms11656 KiB
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define sumof(x) accumulate(all(x), 0ll)

const int N=2e5+10;
int pre[N], suf[N], n, b[N], res[N];
pair<int, int> a[N];

void solve(int tc){
    // cout << "Case #" << tc << ": ";
    cin >> n;
    for (int i=1; i<=n+1; ++i) cin >> a[i].first, a[i].second=i;
    for (int i=1; i<=n; ++i) cin >> b[i];
    sort(a+1, a+n+2);
    sort(b+1, b+n+1);
    for (int i=1; i<=n; ++i) pre[i]=max(pre[i-1], a[i].first-b[i]);
    for (int i=n; i>=1; --i) suf[i]=max(suf[i+1], a[i+1].first-b[i]);
    for (int i=1; i<=n+1; ++i) res[a[i].second]=max(pre[i-1], suf[i]);
    for (int i=1; i<=n+1; ++i) cout << res[i] << ' ';
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int ntests=1;
    // cin >> ntests;
    for (int i=1; i<=ntests; ++i) solve(i);
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...