제출 #567081

#제출 시각아이디문제언어결과실행 시간메모리
567081MajidJust Long Neckties (JOI20_ho_t1)C++17
0 / 100
1 ms212 KiB
#include<bits/stdc++.h>
using namespace std;
 
//Types
using ll = long long;
using db = double;
 
//Vectors
#define pb push_back
#define sz(vec) ((ll)vec.size())
#define all(vec) vec.begin(), vec.end()
 
//things
#define f first
#define s second
const int SMALLINF = 1e9 + 7;
const ll BIGINF = ((ll)1e18) + 7;
#define Speeed ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);

void solve(){

    ll n;
    cin>>n;
    
    vector<pair<ll, ll> > a;
    vector<ll> b(n);
    
    for(ll i = 0; i < n+1; i++){
        
        ll v;
        cin>>v;
        
        a.pb({v, i});
    }
    
    for(ll i = 0; i < n; i++){
        
        cin>>b[i];
    }
    
    sort(all(a));
    sort(all(b));
    
    vector<ll> orig(n);
    ll mx = 0;
    
    for(ll i = n-1; i >= 0; i--){
    
        orig[i] = max(0ll, a[i].f - b[i]);
        mx = max(mx, orig[i]);
    }
    
    
    vector<ll> ans(n+1), ch(n);
    ans[a[n].s] = mx;
    
    for(ll i = n-1; i >= 0; i--){
        
        ans[a[i].s] = max(mx, max(0ll, a[i+1].f - b[i]));
    }
    
    for(ll i = 0; i < n+1; i++)cout<<ans[i]<<" ";
    
}


int main(){
	Speeed
	
    ll t=1;
    // cin>>t;
    
    while(t--){
        
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...