Submission #202722

#TimeUsernameProblemLanguageResultExecution timeMemory
202722achibasadzishviliJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
366 ms18040 KiB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,b[200005],an[200005];
pair<ll,ll>a[200005];
multiset<ll>st;
multiset<ll>::iterator it;
int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    
    for(int i=1; i<=n + 1; i++){
        cin >> a[i].f;
        a[i].s = i;
    }
    
    sort(a + 1 , a + n + 2);
    
    for(int i=1; i<=n; i++){
        cin >> b[i];
    }
    
    sort(b + 1 , b + n + 1);
    
    for(int i=1; i<=n; i++){
        st.insert(max(0LL , a[i + 1].f - b[i]));
    }
    it = st.end();
    it--;
    an[a[1].s] = (*it);
    
    for(int i=2; i<=n + 1; i++){
        st.erase(st.find(max(0LL , a[i].f - b[i - 1])));
        st.insert(max(0LL , a[i - 1].f - b[i - 1]));
        it = st.end();
        it--;
        an[a[i].s] = (*it);
    }
    
    for(int i=1; i<=n + 1; i++)
        cout << an[i] << " ";
    
    
    
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...