This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int MX_N = 2e5+5;
int N;
pair<int,int> A[MX_N];
int B[MX_N];
int P[MX_N], Q[MX_N], ans[MX_N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
FOR(i,1,N+1){
cin >> A[i].first;
A[i].second = i;
}
FOR(i,1,N){
cin >> B[i];
}
sort(A+1,A+1+N+1);
sort(B+1,B+1+N);
FOR(i,1,N){
P[i] = max(P[i-1], max(A[i].first-B[i],0));
}
RFOR(i,N,1){
Q[i] = max(P[i+1], max(A[i+1].first-B[i],0));
}
FOR(i,1,N+1){
ans[A[i].second] = max(P[i-1],Q[i]);
}
FOR(i,1,N+1){
cout << ans[i] << (i==N+1?'\n':' ');
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |