Submission #567069

#TimeUsernameProblemLanguageResultExecution timeMemory
567069haxormanJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
100 ms10020 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mxN = 2e5 + 7;

pair<int,int> a[mxN];
int b[mxN], og[mxN], ans[mxN];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int n;
	cin >> n;

	for (int i = 0; i < n + 1; ++i) {
		cin >> a[i].first;
		a[i].second = i;
	}

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

	sort(a, a + n + 1);	
	for (int i = 0; i < n; ++i) {
		og[a[i].second] = i;
	}

	sort(b, b + n);

	for (int i = n - 1; i >= 0; --i) {
		ans[a[n].second] = max(ans[a[n].second], a[i].first - b[i]);
	}

	for (int i = n - 1; i >= 0; --i) {
		ans[a[i].second] = max(ans[a[i + 1].second], a[i + 1].first - 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...