This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef stack<ll> sll;
typedef queue<ll> qll;
typedef deque<ll> dll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
#define endl '\n'
#define pb push_back
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define BACK(i,a,b) for(int i = a; i >= b; i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define bp __builtin_popcountll
#define gcd __gcd
#define bit(i,n) ((n>>i)&1)
#define setmin(x,y) x=min((x),(y))
#define setmax(x,y) x=max((x),(y))
const int MAXN = (2e5)+5;
// const ll SQRT = 4;
const long long inf = 1e18;
const long long MOD = 998244353;
int n,pre[MAXN],suf[MAXN],b[MAXN],ans[MAXN];
pair<int,int> a[MAXN];
signed main()
{
fastIO
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
cin>>n;
FOR(i,1,n+1) {cin>>a[i].fi; a[i].se=i;}
FOR(j,1,n) cin>>b[j];
sort(b+1,b+1+n);
sort(a+1,a+2+n);
FOR(i,1,n) pre[i]=max(pre[i-1],a[i].fi-b[i]);
// FOR(i,1,n) cout<<pre[i]<<' ';
BACK(i,n+1,2) suf[i]=max(suf[i+1],a[i].fi-b[i-1]);
// FOR(i,2,n+1) cout<<suf[i]<<' ';
FOR(i,1,n+1) ans[a[i].se]=max(pre[i-1],suf[i+1]);
FOR(i,1,n+1) cout<<ans[i]<<' ';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |