#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define foru(i,a,b) for(ll i = a; i <= b; ++i)
#define ford(i,a,b) for(ll i = a; i >= b; --i)
#define vt vector
#define fi first
#define se second
const int N = 200005;
int n;
pair<ll,int>a[N];
ll b[N];
ll ans[N];
ll res1[N];
ll res2[N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
foru(i,0,n){
cin >> a[i].fi;
a[i].se = i;
}
foru(i,0,n-1){
cin >> b[i];
}
sort(a,a+n+1);
sort(b,b+n);
foru(i,0,n-1){
if(i == 0){
res1[i] = max(a[i].fi-b[i],0LL);
} else {
res1[i] = max(res1[i-1],max(a[i].fi-b[i],0LL));
}
}
ford(i,n,1){
if(i == n){
res2[i] = max(a[i].fi-b[i-1],0LL);
} else {
res2[i] = max(res2[i-1],max(a[i].fi-b[i-1],0LL));
}
}
foru(i,0,n){
int ptr = a[i].se;
if(i == 0){
ans[ptr] = res2[1];
} else if(i == n){
ans[ptr] = res1[n-1];
} else {
ans[ptr] = max(res1[i-1],res2[i+1]);
}
}
foru(i,0,n){
cout << ans[i] << " ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |