제출 #1159025

#제출 시각아이디문제언어결과실행 시간메모리
1159025crispxxJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
63 ms13384 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define pb push_back
#define nl '\n'

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n; cin >> n;
	
	vector<int> a(n + 1), b(n);
	
	for(auto &x : a) cin >> x;
	
	for(auto &x : b) cin >> x;
	
	vector<pair<int, int>> v(n + 1);
	
	for(int i = 0; i <= n; i++) {
		v[i] = {a[i], i};
	}
	
	sort(all(v)), sort(all(b));
	
	vector<int> pref(n + 1), suf(n + 2);
	
	for(int i = 0; i < n; i++) {
		pref[i + 1] = max(pref[i], max(0LL, v[i].first - b[i]));
	}
	
	for(int i = n - 1; i >= 0; i--) {
		suf[i] = max(suf[i + 1], max(0LL, v[i + 1].first - b[i]));
	}
	
	// for(int i = 0; i <= n; i++) {
		// cout << v[i].first << ' ';
	// }
	
	// cout << nl;
	
	// for(int i = 0; i <= n; i++) {
		// cout << v[i].second << ' ';
	// }
	
	// cout << nl;
	
	// for(int i = 1; i <= n; i++) {
		// cout << pref[i] << ' ';
	// }
	
	// cout << nl;
	
	vector<int> ans(n + 1);
	
	for(int i = 0; i <= n; i++) {
		ans[v[i].second] = max(pref[i], suf[i]);
	}
	
	for(auto i : ans) cout << i << ' ';
	cout << nl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...