Submission #1297947

#TimeUsernameProblemLanguageResultExecution timeMemory
1297947kiteyuJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
64 ms6896 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;
const int N = 2e5;

int n;
pair<int,int> a[N+5];
int b[N+5],c1[N+5],c2[N+5];
int ans[N+5];

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1 ; i <= n + 1 ; ++i){
        cin >> a[i].fi;
        a[i].se = i;
    }
    sort(a+1,a+2+n);
    for(int i = 1 ; i <= n ; ++i)
        cin >> b[i];
    sort(b+1,b+1+n);
    a[n+2] = {b[n],0};
    for(int i = 1 ; i <= n; ++i){
        c1[i] = a[i].fi - b[i];
        c2[i] = a[i+1].fi - b[i];
    }
    for(int i = 2 ; i <= n + 1 ; ++i){
        c1[i] = max(c1[i-1],c1[i]);
//        cout << i << ',' << c1[i] << '\n';
    }

    for(int i = n ; i >= 1 ; --i){
        c2[i] = max(c2[i],c2[i+1]);
//        cout << i << '.' << c2[i] << '\n';
    }

    for(int i = 1 ; i <= n + 1 ; ++i){
        int res = max(c1[i-1],c2[i]);
        ans[a[i].se] = res;
    }
    for(int i = 1 ; i <= n + 1 ; ++i)
        cout << ans[i] << ' ';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...