Submission #1198343

#TimeUsernameProblemLanguageResultExecution timeMemory
1198343TahirAliyevJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
62 ms10052 KiB
#include <bits/stdc++.h>

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define ld long double
#define ll long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
const int oo = 1e18 + 9;
const int MAX = 5000 + 5, LOGMAX = 20, B = 441, MOD = 998244353;


void solve(){
    int n; cin >> n;
    pii arr[n + 2];
    int b[n + 1];
    for(int i = 1; i <= n + 1; i++){
        cin >> arr[i].first;
        arr[i].second = i;
    } 
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    sort(arr + 1, arr + n + 2);
    sort(b + 1, b + n + 1);
    int suf[n + 3];
    suf[n + 2] = -oo;
    for(int i = n + 1; i >= 2; i--){
        suf[i] = max(suf[i + 1], max(0ll, arr[i].first - b[i - 1]));
    }
    vector<int> ans(n + 2, 0);
    int mx = -oo;
    for(int i = 1; i <= n + 1; i++){
        ans[arr[i].second] = max(mx, suf[i + 1]);
        mx = max(mx, arr[i].first - b[i]);
    }
    for(int i = 1; i <= n + 1; i++) cout << ans[i] << ' ';
    cout << '\n';
}   

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...