제출 #860995

#제출 시각아이디문제언어결과실행 시간메모리
860995phoenix0423Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
295 ms19536 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
const int maxn = 4e5 + 5;
const int INF = 1e9;

int main(void){
	// fastio;
	int n;
	cin>>n;
	vector<pll> a(n + 1);
	vector<ll> b(n);
	for(int i = 0; i < n + 1; i++){
		int x;
		cin>>x;
		a[i] = {x, i};
	}
	for(int i = 0; i < n; i++) cin>>b[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	multiset<int> st;
	for(int i = 0; i < n; i++) st.insert(max(0LL, a[i + 1].f - b[i]));
	vector<int> ans(n + 1);
	for(int i = 0; i < n + 1; i++){
		auto [val, id] = a[i];
		ans[id] = *st.rbegin();
		if(i == n) break;
		st.erase(st.find(max(0LL, a[i + 1].f - b[i])));
		st.insert(max(0LL, a[i].f - b[i]));
	}
	for(int i = 0; i < n + 1; i++) cout<<ans[i]<<" ";
	cout<<"\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...