제출 #1347003

#제출 시각아이디문제언어결과실행 시간메모리
1347003Born_To_LaughJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
50 ms6920 KiB
// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(AC) AC.begin(), AC.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
[[maybe_unused]] const int MOD = 998244353, INF = 1e9 + 7;

const int maxn = 2e5 + 10;
int n;
int b[maxn];
pair<int, int> a[maxn];
int pref[maxn], suff[maxn];
int ans[maxn];
void solve(){
    cin >> n;
    for(int i=1; i<=n+1; ++i){
        cin >> a[i].fi;
        a[i].se = i;
    }
    for(int i=1; i<=n; ++i) cin >> b[i];
    sort(a + 1, a + 2 + n);
    sort(b + 1, b + 1 + n);
    for(int i=1; i<=n; ++i){
        pref[i] = max(pref[i - 1], a[i].fi - b[i]);
    }
    for(int i=n + 1; i>=2; --i){
        suff[i] = max(suff[i + 1], a[i].fi - b[i - 1]);
    }
    for(int i=1; i<=n + 1; ++i){
        ans[a[i].se] = max(pref[i - 1], suff[i + 1]);
    }
    for(int i=1; i<=n+1; ++i) cout << ans[i] << ' ';
}
signed main(){
    // freopen("inp.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...