Submission #969170

#TimeUsernameProblemLanguageResultExecution timeMemory
969170yellowtoadJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
183 ms13908 KiB
#include <iostream>
#include <algorithm>
#define f first
#define s second
using namespace std;

long long n, b[200010], maxx[200010], maxxx, ans[200010];
pair<long long,int> a[200010];

int main() {
	cin >> n;
	for (int i = 1; i <= n+1; i++) {
		cin >> a[i].f;
		a[i].s = i;
	}
	for (int i = 1; i <= n; i++) cin >> b[i];
	sort(a+1,a+n+2);
	sort(b+1,b+n+1);
	for (int i = n; i >= 1; i--) maxx[i] = max(maxx[i+1],a[i+1].f-b[i]);
	for (int i = 1; i <= n+1; i++) {
		ans[a[i].s] = max(maxxx,maxx[i]);
		maxxx = max(maxxx,a[i].f-b[i]);
	}
	for (int i = 1; i <= n+1; i++) cout << ans[i] << " ";
	cout << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...