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>
#define f first
#define s second
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N; cin >> N;
vector<pair<int,int>> A(N+1);
vector<int> B(N);
for(int i = 0;i<=N;++i){
cin >> A[i].f;
A[i].s = i;
}
for(int i = 0;i<N;++i) cin >> B[i];
sort(A.begin(),A.end()); sort(B.begin(),B.end());
vector<int> pref(N);
for(int i = 0;i<N;++i){
if(i != 0) pref[i] = max(pref[i-1],max(A[i].f-B[i],0));
else pref[i] = max(A[i].f-B[i],0);
//cout << pref[i] << "\n";
}
vector<int> suf(N+1);
for(int i = N;i>=1;--i){
if(i != N) suf[i] = max(suf[i+1],max(A[i].f-B[i-1],0));
else suf[i] = max(A[i].f-B[i-1],0);
}
vector<int> ans(N+1);
for(int i = 0;i<=N;++i){
if(i != N && i != 0) ans[A[i].s] = max(suf[i+1],pref[i-1]);
else if(i == N) ans[A[i].s] = pref[i-1];
else ans[A[i].s] = suf[i+1];
}
for(int i = 0;i<=N;++i) cout << ans[i] << " ";
cout << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |