제출 #202047

#제출 시각아이디문제언어결과실행 시간메모리
202047khohkoJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
501 ms17932 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ARRS ((ll)(4e5+100))
#define fr first
#define sc second
#define pb push_back
#define MX ((ll)(1e9+100))
#define MAX ((ll)(1e18+100))

ll n;
pair<ll,ll> a[ARRS];
ll b[ARRS];
ll ans[ARRS];
int main(){
	cin>>n;
	for(int i=0; i<=n; i++){
		cin>>a[i].fr;
		a[i].sc=i;
	}
	for(int i=0; i<n; i++){
		cin>>b[i];
	}
	sort(a,a+n+1);
	sort(b,b+n);
	multiset<ll> st;
	for(int i=0; i<n; i++)
		st.insert(a[i].fr-b[i]);
	for(int i=n; i>=0; i--){
		ans[a[i].sc]=*(--st.end());
		if(i)
		st.erase(st.find(a[i-1].fr-b[i-1]));
		st.insert(a[i].fr-b[i-1]);
	}
	for(int i=0; i<=n; i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...