제출 #762935

#제출 시각아이디문제언어결과실행 시간메모리
762935vjudge1Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
173 ms8400 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

struct gay
{
    ll value, index;
};

bool cmp(const gay &a, const gay &b)
{
    return a.value < b.value;
}
int main()
{
    ll n;
    cin >> n;
    gay a[n + 2];
    ll b[n + 1];
    ll maxt = -1;

    for (ll i = 1; i <= n + 1; ++i) 
    {
        cin >> a[i].value;
        a[i].index = i;
    }
    
    for (ll i = 1; i <= n; ++i) cin >> b[i];

    sort(a + 1, a + n + 2, cmp);
    sort(b + 1, b + n + 1);
    for (ll i = 1; i <= n; ++i)
    {
        ll tmp = a[i].value - b[i];
        maxt = max(maxt, max(tmp, 0LL));
    }
    //cout << maxt << endl;
    ll ans[n + 2];
    ans[a[n + 1].index] = maxt; 

    for (ll i = n; i >= 1; --i)
    {
        maxt = max(maxt, max(a[i + 1].value - b[i], 0LL));
        ans[a[i].index] = maxt;
        //cout << a[n + 1].value << " " << b[i] << " " << maxt << ' ';
    }

    for (ll i = 1; i <= n + 1; ++i) cout << ans[i] << ' ';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...