Submission #297797

#TimeUsernameProblemLanguageResultExecution timeMemory
297797balbitJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
110 ms9336 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define f first
#define s second

#define pb push_back
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define MX(a,b) a=max(a,b)
#ifdef BALBIT
#define bug(...) cerr<<"#"<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y){cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif // BALBIT

const int maxn = 3e5+5;

signed main(){
    IOS();
    bug(1,2);
    int n; cin>>n;
    vector<pii> a(n+1);
    vector<int> r(n+1);
    vector<int> b(n);
    for (int i = 0; i<n+1; ++i) cin>>a[i].f, a[i].s = i;
    sort(ALL(a));
    for (int i = 0; i<n; ++i) cin>>b[i];
    sort(ALL(b));
    int ts = 0;
    for (int i = 0; i<n; ++i) {
        MX(ts , max(a[i].f-b[i],0));
        MX(r[a[i+1].s] , ts);
        bug(ts);
    }

    ts = 0;
    for (int i = n; i>0; --i) {
        MX(ts , max(a[i].f-b[i-1],0));
        MX(r[a[i-1].s] , ts);
        bug(ts);
    }

    for (int i = 0; i<=n; ++i) {
        cout<<r[i]<<' ';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...