Submission #1345088

#TimeUsernameProblemLanguageResultExecution timeMemory
1345088thaibaotran555Just Long Neckties (JOI20_ho_t1)C++20
100 / 100
53 ms6888 KiB
///TRAN THAI BAO :3

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define maxN 200007

typedef pair<int, int> pii;

int n;
pii a[maxN];
int b[maxN];
int l[maxN] = {0};
int r[maxN] = {0};
int ans[maxN];

void solve()
{
    cin >> n;
    for(int i = 1; i <= n+1; i++)
    {
        cin >> a[i].first;
        a[i].second = i;
    }
    for(int j = 1; j <= n; j++)
        cin >> b[j];
    sort(a+1, a+n+2);
    sort(b+1, b+n+1);
    for(int i = 1; i <= n; i++)
        l[i] = max(l[i-1], max(a[i].first-b[i], 0));
    for(int i = n+1; i >= 2; i--)
        r[i] = max(r[i+1], max(a[i].first-b[i-1], 0));
    for(int i = 1; i <= n+1; i++)
    {
        int curPos = a[i].second;
        ans[curPos] = max(l[i-1], r[i+1]);
    }
    for(int i = 1; i <= n+1; i++)
        cout << ans[i] << " ";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...