Submission #589940

#TimeUsernameProblemLanguageResultExecution timeMemory
589940tamthegodJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
115 ms17056 KiB
#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, a[maxN], b[maxN];
int id[maxN];
int c[maxN], d[maxN];
int res[maxN];
int suff[maxN];
void ReadInput()
{
    cin >> n;
    for(int i=1; i<=n+1; i++) cin >> a[i];
    for(int i=1; i<=n; i++) cin >> b[i];
}
void Solve()
{
    sort(b + 1, b + n + 1);
    iota(id + 1, id + n + 2, 1);
    sort(id + 1, id + n + 2, [](int i, int j)
    {
        return a[i] < a[j];
    });
    for(int i=1; i<=n; i++)
        c[i] = a[id[i]] - b[i];
    for(int i=2; i<=n+1; i++)
        d[i] = a[id[i]] - b[i - 1];
    for(int i=n+1; i>=2; i--)
        suff[i] = max(suff[i + 1], d[i]);
    int _max = 0;
    for(int i=1; i<=n+1; i++)
    {
        res[id[i]] = max(_max, suff[i + 1]);
        _max = max(_max, c[i]);
    }
    for(int i=1; i<=n+1; i++) cout << res[i] << " ";
}
int32_t main()
{
   // freopen("x.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...