Submission #978337

#TimeUsernameProblemLanguageResultExecution timeMemory
978337AmaarsaaJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
89 ms18612 KiB
#include<bits/stdc++.h>

using namespace std;
using ll = long long ;
int main() {
//	freopen("moocast.in", "r", stdin);
//	freopen("moocast.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, i, s;
	cin >> n;
	ll ans[n + 2];
	pair < ll, ll > A[n + 2];
	ll b[n + 2], aragshaa[n + 2], uragshaa[n + 2], Pre[n + 2], Suf[n + 2];
	for (i = 1; i <= n + 1; i ++) {
		cin >> A[i].first;
		A[i].second = i;
	}
	for (i = 1; i <= n; i ++) {
		cin >> b[i];
	}
	sort ( b + 1, b + n + 1);
	sort ( A + 1, A + n + 2);
	for (i = 1; i <= n; i ++) {
		uragshaa[i] = max(0ll, A[i].first - b[i]);
		aragshaa[i] = max(0ll, A[i + 1].first - b[i]);
	}
	Pre[0]= 0;
	for (i = 1; i <=n; i ++) {
		Pre[i]= max(Pre[i - 1] , uragshaa[i]);
	}
	Suf[n + 1] = 0;
	for (i = n; i >= 1; i --) {
		Suf[i] = max(Suf[i + 1] , aragshaa[i]);
	}
	for (i = 1; i <= n + 1; i ++) {
		s = max(Suf[i] , Pre[i - 1]);
		ans[A[i].second] = s;
	}
	for (i = 1; i<= n + 1; i ++) cout << ans[i] << " ";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...