Submission #1144657

#TimeUsernameProblemLanguageResultExecution timeMemory
1144657NomioJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
155 ms15548 KiB
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n + 2), b(n + 1), A(n + 2);
	for(int i = 1; i <= n + 1; i++) {
		cin >> a[i];
		A[i] = a[i];
	}
	A[0] = a[0] = 0;
	for(int i = 1; i <= n; i++) {
		cin >> b[i];
	}
	b[0] = 0;
	sort(A.begin(), A.end());
	sort(b.begin(), b.end());
	vector<int> bmx(n + 3, -1e9), emx(n + 3, -1e9);
	for(int i = 1; i <= n; i++) {
		bmx[i] = max({0, bmx[i - 1], A[i] - b[i]});
	}
	for(int i = n + 1; i > 1; i--) {
		emx[i] = max({0, emx[i + 1], A[i] - b[i - 1]});
	}
	map<int, int> m;
	for(int i = 1; i <= n + 1; i++) {
		m[A[i]] = i;
	}
	for(int i = 1; i <= n + 1; i++) {
		int x = m[a[i]];
		cout << max({0, bmx[x - 1], emx[x + 1]}) << ' ';
	}
	cout << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...