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<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int const N = 200005;
int b[N], premax[N];
typedef pair<int, int> pii;
pii a[N];
int ans[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for(int i = 0; i <= n; i++){
cin >> a[i].first;
a[i].second = i;
}
for(int i = 0; i < n; i++){
cin >> b[i];
}
sort(b, b + n);
sort(a, a + n + 1);
premax[0] = a[0].first - b[0];
for(int i = 1; i < n; i++){
premax[i] = max(premax[i - 1], a[i].first - b[i]);
}
int prem = 0;
for(int i = n; i >= 0; i--){
prem = max(prem, a[i + 1].first - b[i]);
int maxn = 0;
if(i == 0){
maxn = prem;
}else{
maxn = max(prem, premax[i - 1]);
}
ans[a[i].second] = maxn;
}
for(int i = 0; i <= n; i++){
cout << ans[i] << '\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... |