제출 #724259

#제출 시각아이디문제언어결과실행 시간메모리
724259CookieJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
272 ms21132 KiB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("WINTER.inp");
ofstream fout("WINTER.out");
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
const ll mod = 1e9 + 7;
const int mxn = 2e5 + 5, mxm = 1e5;
int n;
ll ans[mxn + 1];
signed main(){
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    vt<pair<ll, int>>b;
    vt<ll>a;
    forr(i, 1, n + 2){
        int x; cin >> x;
        b.pb(make_pair(x, i));
    }
    sort(b.begin(), b.end());
    forr(i, 1, n + 1){
        int x; cin >> x;
        a.pb(x);
    }
    sort(a.begin(), a.end());
    multiset<ll>ms;
    for(int i = 0; i < n; i++){
        ms.insert(max(b[i + 1].first - a[i], (ll)0));
    }
    ans[b[0].se] = *ms.rbegin();
    
    for(int i = 1; i <= n; i++){
        // if choosen if i
        ms.erase(ms.find(max(b[i].first - a[i - 1], (ll)0)));
        ms.insert(max(b[i - 1].first - a[i - 1], (ll)0));
        
        ans[b[i].second] = *ms.rbegin();
    }
    forr(i, 1, n + 2)cout << ans[i] << ' ';
    return(0);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...