제출 #922888

#제출 시각아이디문제언어결과실행 시간메모리
922888dimashhhJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
103 ms10836 KiB
#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 12, MOD = 1e9 + 7;

typedef long long ll;

int n,a[N],b[N],p[N],pref[N],sf[N],res[N];
void test(){
    cin >> n;
    for(int i = 1;i <= n + 1;i++){
        cin >> a[i];
        p[i] = i;
    }
    sort(p + 1,p + n + 2,[&](int x,int y){
        return a[x] < a[y];
    });
    sort(a + 1,a + n +2 );
    for(int i = 1;i <= n;i++){
        cin >> b[i];
    }
    sort(b + 1,b + n + 1);
    for(int i = 1;i <= n;i++){
        pref[i] = max(pref[i - 1],max(0,a[i] - b[i]));
    }
    for(int i = n;i >= 1;i--){
        sf[i] = max(sf[i + 1],a[i + 1] - b[i]);
    }
    for(int i = 1;i <= n + 1;i++){
        res[p[i]] =max(pref[i - 1],sf[i]);
    }
    for(int i = 1;i <= n + 1;i++){
        cout << res[i] << ' ';
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int T = 1;
//    cin >> T;
    while (T--)
        test();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...