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 N = 2e5 + 12, MOD = 1e9 + 7;
typedef long long ll;
int n,a[N],b[N],p[N],pref[N],sf[N],res[N];
void test(){
cin >> n;
for(int i = 1;i <= n + 1;i++){
cin >> a[i];
p[i] = i;
}
sort(p + 1,p + n + 2,[&](int x,int y){
return a[x] < a[y];
});
sort(a + 1,a + n +2 );
for(int i = 1;i <= n;i++){
cin >> b[i];
}
sort(b + 1,b + n + 1);
for(int i = 1;i <= n;i++){
pref[i] = max(pref[i - 1],max(0,a[i] - b[i]));
}
for(int i = n;i >= 1;i--){
sf[i] = max(sf[i + 1],a[i + 1] - b[i]);
}
for(int i = 1;i <= n + 1;i++){
res[p[i]] =max(pref[i - 1],sf[i]);
}
for(int i = 1;i <= n + 1;i++){
cout << res[i] << ' ';
}
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int T = 1;
// cin >> T;
while (T--)
test();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |