제출 #826314

#제출 시각아이디문제언어결과실행 시간메모리
826314xinkJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
156 ms7016 KiB
#include <iostream>
#include <vector>
#include <utility>
#include <sstream>
#include <climits>
#include <cstring>
#include <algorithm>
#define ll long long
#define ld long double
using namespace std;
const ll mod = 1e9 + 7;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int maxn = 2e5 + 5;
ii a[maxn];
int b[maxn], pref[maxn], suff[maxn], ans[maxn];

void solve()
{
    int n;
    cin >> n;
    for (int i = 0; i <= n; i++)
    {
        cin >> a[i].first;
        a[i].second = i;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    sort(a, a + n + 1);
    sort(b, b + n);
    pref[0] = max(a[0].first - b[0], 0);
    for (int i = 1; i < n; i++)
    {
        pref[i] = max(pref[i - 1], max(a[i].first - b[i], 0));
    }
    suff[n] = max(a[n].first - b[n - 1], 0);
    for (int i = n - 1; i > 0; i--)
    {
        suff[i] = max(suff[i + 1], max(a[i].first - b[i - 1], 0));
    }
    for (int i = 0; i <= n; i++)
    {
        int oddity = 0;
        if (i != 0)
        {
            oddity = max(oddity, pref[i - 1]);
        }
        if (i != n)
        {
            oddity = max(oddity, suff[i + 1]);
        }
        ans[a[i].second] = oddity;
    }
    for (int i = 0; i <= n; i++) {
        cout << ans[i] << " ";
    }
}

int main()
{
    // freopen("input_text", "r", stdin);
    // freopen("output_text", "w", stdout);
    // ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t-- > 0)
        solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...