Submission #256538

#TimeUsernameProblemLanguageResultExecution timeMemory
256538jainbot27Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
331 ms11028 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
int n, b[N], p[N], s[N], ans[N];
pair<int, int> a[N];
int main(){
	cin >> n;
	for(int i =1;i <= n + 1; i++){
		cin >> a[i].first;
		a[i].second = 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 = 1 ; i <= n; i++){
		p[i] = max(p[i-1], max(a[i].first - b[i], 0));
	}
	for(int i = n + 1; i > 1; i--){
		s[i] = max(s[i + 1], max(a[i].first - b[i-1], 0));	
	}
	for(int i =1  ; i <= n + 1; i++){
		ans[a[i].second] = max(p[i-1], s[i + 1]);
	}
	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...