제출 #1174876

#제출 시각아이디문제언어결과실행 시간메모리
1174876Hamed_GhaffariJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
59 ms6216 KiB
#include<bits/stdc++.h>
using namespace std;

const int MXN = 2e5+5;
int n, b[MXN], dp[MXN], ans[MXN];
pair<int, int> a[MXN];
int32_t main() {
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i=1; i<=n+1; i++) cin >> a[i].first, a[i].second=i;
    for(int i=1; i<=n; i++) cin >> b[i];
    sort(a+1, a+n+2);
    sort(b+1, b+n+1);
    for(int i=1; i<=n; i++) dp[i] = max(dp[i-1], a[i].first-b[i]);
    int val=0;
    for(int i=n+1; i>=1; i--) {
        ans[a[i].second] = max(dp[i-1], val);
        val = max(val, a[i].first-b[i-1]);
    }
    for(int i=1; i<=n+1; i++) cout << ans[i] << ' ';
    cout << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...