제출 #536013

#제출 시각아이디문제언어결과실행 시간메모리
536013browntoadJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
144 ms10816 KiB
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define RREP1(i,n) for (int i=(n); i>=1; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pdd pair<double ,double>
#define pcc pair<char, char> 
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
 
const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 1e9+7;
const ll maxn=5005;
const double PI=acos(-1);
 
ll pw(ll x, ll p, ll m=mod){
    ll ret=1;
    while (p>0){
        if (p&1){
            ret*=x;
            ret%=m;
        }
        x*=x;
        x%=m;
        p>>=1;
    }
    return ret;
}
 
ll inv(ll a, ll m=mod){
    return pw(a,m-2);
}
 
//=======================================================================================

struct typ{
    int val;
    int id;
    int ans;
};
bool cmp(typ a, typ b){
    return a.val<b.val;
}
bool cmp2(typ a, typ b){
    return a.id<b.id;
}
signed main (){
    IOS();
    int n; cin>>n;
    vector<typ> vc(n+1);
    REP(i,n+1) {
        cin>>vc[i].val;
        vc[i].id=i;
        vc[i].ans=0;
    }
    sort(ALL(vc), cmp);
    vector<int> len(n);
    REP(i,n) cin>>len[i];
    sort(ALL(len));
    vector<int> pf(n);
    REP(i,n){
        pf[i]=vc[i].val-len[i];
        if (i!=0){
            pf[i]=max(pf[i-1], pf[i]);
        }
    }
    int prev=0;
    vc[n].ans=max(pf[n-1], 0ll);
    RREP(i,n){
        int cur=prev;
        cur=max(cur, vc[i+1].val-len[i]);
        if (i>0){
            cur=max(cur, pf[i-1]);
        }
        vc[i].ans=cur;
        prev=max(prev, vc[i].ans);
    }
    sort(ALL(vc), cmp2);
    REP(i,n+1){
        cout<<vc[i].ans<<endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...