제출 #475906

#제출 시각아이디문제언어결과실행 시간메모리
475906ymmJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
318 ms19396 KiB
///
///   Let the voice of love take you higher!
///

#define _USE_MATH_DEFINES
#define FAST ios::sync_with_stdio(false),cin.tie(0);
#include <bits/stdc++.h>
#define Loop(x, l, r) for(ll x = ll(l); x < ll(r); ++x)
#define LoopR(x, l, r) for(ll x = ll(r)-1; x >= ll(l); --x)
#define all(x) x.begin(), x.end()
#define Kill(x) exit((cout << (x) << '\n', 0))
#define YN(flag) ((flag)? "YES": "NO")
#define F first
#define S second
typedef          long long   ll;
typedef unsigned long long  ull;
typedef std::pair<int,int>  pii;
typedef std::pair<ll ,ll >  pll;
using namespace std;

const int N = 200010;
pii a[N];
int b1[N];
int b2[N];
int ans[N];
set<pii, greater<pii>> s;
int n;


int main()
{
    FAST;
    cin >> n;
    Loop(i,0,n+1) cin >> a[i].F, a[i].S=i;
    Loop(i,0,n) cin >> b1[i];
    sort(b1, b1+n);
    sort(a, a+n+1);
    Loop(i,0,n) b2[i] = a[i+1].F;
    s.insert({0, -1});
    Loop(i,0,n) s.emplace(b2[i]-b1[i], i);
    Loop(i,0,n+1)
    {
        ans[a[i].S] = s.begin()->F;
        if(i==n) break;
        s.erase({b2[i]-b1[i],i});
        b2[i] = a[i].F;
        s.insert({b2[i]-b1[i],i});
    }
    Loop(i,0,n+1) cout << ans[i] << ' ';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...