Submission #244845

#TimeUsernameProblemLanguageResultExecution timeMemory
244845vioalbertJust Long Neckties (JOI20_ho_t1)C++14
9 / 100
1090 ms7916 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 2e5+5;
int n;
int b[N], odd[N], ans[N];
vector<pair<int, int>> a;

void read() {
	cin >> n;
	for(int i = 0; i <= n; i++) {
		int x; cin >> x;
		a.push_back({x, i});
	}
	sort(a.begin(), a.end());
	for(int i = 0; i < n; i++)
		cin >> b[i];
	sort(b, b+n);
}

void solve() {
	for(int i = 0; i < n; i++) {
		odd[i] = max(0, a[i+1].first - b[i]);
	}

	for(int i = 0; i < n; i++) {
		int& mx = ans[a[i].second] = 0;
		for(int j = 0; j < n; j++)
			mx = max(mx, odd[j]);
		odd[i] = max(0, a[i].first - b[i]);
	}
	int& mx = ans[a[n].second] = 0;
	for(int j = 0; j < n; j++)
		mx = max(mx, odd[j]);

	for(int i = 0; i < n+1; i++)
		cout << ans[i] << " \n"[i==n];
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	read();
	solve();
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...