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;
#define int long long
const int INF = 1e13;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> arr(2*n+1);
for(int i=1;i<=2*n;i++)cin>>arr[i];
vector<int> B(n);
for(int&i:B)cin>>i;
sort(B.begin(),B.end());
vector<int> C(n);
for(int&i:C)cin>>i;
sort(C.begin(),C.end());
auto check_support = [&](int x){
// return a vector of bool of 1..n signifying if it works or not
// check array against B
vector<int> works(n+2);
for(int i=1;i<=n;i++){
auto it1 = lower_bound(B.begin(),B.end(),arr[i]-x);
auto it2 = upper_bound(B.begin(),B.end(),arr[i]+x);
if(it1==it2)continue;
auto en = it1-B.begin();
auto st = it2-B.begin()-1;
works[max(i-st,1ll)]++;
works[max(min(i-en+1,i+1),1ll)]--;
}
for(int i=n+1;i<2*n;i++){
if(abs(arr[i]-B[2*n-i])>x)continue;
works[i-n+1]++;
}
for(int i=1;i<=n;i++)works[i]+=works[i-1];
vector<bool> res(n+1);
for(int i=1;i<=n;i++)res[i]=works[i]==n;
return res;
};
auto actcheck = [&](int x){
auto t1 = check_support(x);
swap(B,C);
vector<int> newarr(2*n+1);
for(int i=1;i<=n;i++)newarr[i+n]=arr[i];
for(int i=n+1;i<=2*n;i++)newarr[i-n]=arr[i];
for(int&i:B)i*=-1;
for(int&i:newarr)i*=-1;
reverse(B.begin(),B.end());
swap(newarr,arr);
auto t2 = check_support(x);
swap(newarr,arr);
reverse(B.begin(),B.end());
for(int&i:B)i*=-1;
swap(B,C);
for(int i=1;i<=n;i++)if(t1[i] and t2[i])return true;
return false;
};
auto check = [&](int x){
if(actcheck(x))return true;
swap(B,C);
if(actcheck(x))return true;
return false;
};
int ans = 0;
for(int jump=536870912;jump;jump/=2){
if(!check(jump+ans-1))ans+=jump;
}
cout << ans << '\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |