Submission #532140

#TimeUsernameProblemLanguageResultExecution timeMemory
532140alanlJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
97 ms11672 KiB
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define rep(X, a,b) for(int X=a;X<b;++X)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (int)(a).size()
#define NL "\n"
using namespace std;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef long long ll;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << "," << p.second << ')'; }
template<typename A> ostream& operator<<(ostream &os, const vector<A> &p){
	for(const auto &a:p)
		os << a << " ";
	os << "\n";
	return os;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	vector<pll> a(n+1);
	vector<ll> b(n);
	rep(i,0,n+1){
		cin>>a[i].F;
		a[i].S=i;
	}
	rep(i,0,n) cin>>b[i];
	sort(ALL(a));
	sort(ALL(b));
	vector<ll> inc(n+1, 0);
	vector<ll> up(n+1);
	inc[n-1]=max(a[n].F-b[n-1],0ll);
	up[0]=max(a[0].F-b[0], 0ll);
	for(int i=n-2;i>=0;--i)
		inc[i]=max(inc[i+1], a[i+1].F-b[i]);
	for(int i=1;i<n;++i)
		up[i]=max(up[i-1], a[i].F-b[i]);
	vector<ll> ans(n+1);
	ans[a[0].S]=inc[0];
	for(int i=1;i<n+1;++i){
		ans[a[i].S]=max(up[i-1],inc[i]);
	}
	rep(i,0,n+1) cout<<ans[i]<<" ";
	cout<<NL;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...