Submission #392648

#TimeUsernameProblemLanguageResultExecution timeMemory
392648wind_reaperJust Long Neckties (JOI20_ho_t1)C++17
0 / 100
1 ms204 KiB
#include <bits/stdc++.h>

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	
	int n; 
	cin >> n;

	vector<int> A(n+1), B(n), O(n+1), ans(n+1);

	for(int i = 0; i <= n; i++){
		cin >> A[i];
		O[i] = i;
	}
	for(int i = 0; i < n; i++)
		cin >> B[i];

	sort(B.begin(), B.end());
	sort(O.begin(), O.end(), [&](int i, int j){
		return A[i] < A[j];
	});

	vector<int> pref(n+1), suf(n+1);

	for(int i = 0; i < n; i++)
		pref[i+1] = max(pref[i], abs(A[O[i]] - B[i]));

	for(int i = n; i > 0; --i)
		suf[i-1] = max(suf[i], abs(A[O[i]] - B[i-1]));

	for(int i = 0; i < n+1; i++)
		ans[O[i]] = max(pref[i], suf[i]);

	for(int i : ans)
		cout << i << ' ';

	return 0; 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...