제출 #873501

#제출 시각아이디문제언어결과실행 시간메모리
873501NintsiChkhaidzeJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
83 ms11032 KiB
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define left (h<<1),l,((l + r)>>1)
#define right ((h<<1)|1),((l + r)>>1) + 1,r
#define pii pair<int,int>
using namespace std;

const int N = 2e5 + 5;
pii a[N];
int b[N],p[N],s[N],ans[N];

signed main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    
    int n;
    cin>>n;

    for (int i = 1; i <= n + 1; i++){
        cin >> a[i].f;
        a[i].s=i;
    }

    for (int i = 1; i <= n; i++)
        cin >> b[i];
    sort(b+1,b+n+1);
    sort(a+1,a+n+2);

    for (int i = 1; i <= n; i++)
        p[i] = max(p[i - 1],a[i].f - b[i]);

    for (int i = n; i >= 1; i--){
        s[i] = max(s[i + 1],a[i + 1].f - b[i]);
    }

    for (int i = 1; i <= n + 1; i++){
        ans[a[i].s] = max(p[i - 1],s[i]);
    }

    for (int i=1;i<=n+1;i++)
        cout<<ans[i]<<" ";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...