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;
const int MM = 2e5+5;
int n; long long pref[MM],suff[MM],c[MM],a[MM],b[MM],org[MM];
map<int,int> pos;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i = 1; i <= n+1; i++){
cin >> a[i];
org[i] = a[i];
}
for(int i = 1; i <= n; i++){
cin >> b[i];
}
sort(b+1,b+1+n); sort(a+1,a+2+n);
for(int i = 1; i <= n+1; i++){
pos[a[i]] = i;
}
pref[0] = -1e18;
for(int i = 1; i <= n; i++){
pref[i] = max(pref[i-1],max(0ll,a[i]-b[i]));
}
suff[n+2] = -1e18;
for(int i = n+1; i >= 2; i--){
suff[i] = max(suff[i+1],max(0ll,a[i]-b[n-(n+1-i)]));
}
for(int i = 1; i <= n+1; i++){
int p = pos[org[i]];
cout << max(pref[p-1],suff[p+1]) << " \n"[i==n+1];
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |