Submission #702463

#TimeUsernameProblemLanguageResultExecution timeMemory
702463Koful123Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
95 ms15504 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
 
void solve(){

	int n;
	cin >> n;

	vector<pair<int,int>> a(n + 1);
	for(int i = 0; i < n + 1; i++){
		cin >> a[i].ff; a[i].ss = i;
	}

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

	sort(all(a)); sort(all(b));
	vector<int> one(n + 1),two(n + 2);
	for(int i = 0; i < n; i++){
		one[i] = max((i > 0 ? one[i - 1] : 0),a[i].ff - b[i]);
	}
	for(int i = n; i >= 1; i--){
		two[i] = max(two[i + 1],a[i].ff - b[i - 1]);
	}

	vector<int> res(n + 1);
	for(int i = 0; i < n + 1; i++){
		res[a[i].ss] = max((i + 1 < n + 1 ? two[i + 1] : 0),(i > 0 ? one[i - 1] : 0));
	}

	for(int x : res){
		cout << x << ' ';
	}
}
 
signed main(){ 
 
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	int t = 1;
//	cin >> t;
 
	while(t--)
		solve();
 	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...