Submission #900149

#TimeUsernameProblemLanguageResultExecution timeMemory
900149andrei_iorgulescuJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
74 ms18768 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int n,b[200005];
pair<int,int> a[200005];
int ans[200005];
int d1[200005],d2[200005];
int maxpref[200005],maxsuf[200005];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    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(b + 1,b + n + 1);
    sort(a + 1,a + n + 2);
    for (int i = 1; i <= n; i++)
        d1[i] = abs(a[i].first - b[i]);
    for (int i = 1; i <= n; i++)
        d2[i] = abs(a[i + 1].first - b[i]);
    maxpref[0] = 0;
    maxsuf[n + 1] = 0;
    for (int i = 1; i <= n; i++)
        maxpref[i] = max(maxpref[i - 1],a[i].first - b[i]);
    for (int i = n; i >= 1; i--)
        maxsuf[i] = max(maxsuf[i + 1],a[i + 1].first - b[i]);
    for (int i = 1; i <= n + 1; i++)
        ans[a[i].second] = max(maxpref[i - 1],maxsuf[i]);
    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...