#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 |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
360 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
360 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
360 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1237 ms |
28576 KB |
Output is correct |
2 |
Correct |
1030 ms |
25056 KB |
Output is correct |
3 |
Correct |
824 ms |
20844 KB |
Output is correct |
4 |
Correct |
1029 ms |
28460 KB |
Output is correct |
5 |
Correct |
994 ms |
25056 KB |
Output is correct |
6 |
Correct |
26 ms |
1248 KB |
Output is correct |
7 |
Correct |
882 ms |
29172 KB |
Output is correct |
8 |
Correct |
866 ms |
23964 KB |
Output is correct |
9 |
Correct |
786 ms |
28580 KB |
Output is correct |
10 |
Correct |
1177 ms |
28572 KB |
Output is correct |
11 |
Correct |
1152 ms |
28580 KB |
Output is correct |
12 |
Correct |
1051 ms |
26412 KB |
Output is correct |
13 |
Correct |
1140 ms |
25076 KB |
Output is correct |
14 |
Correct |
927 ms |
28516 KB |
Output is correct |
15 |
Correct |
730 ms |
24964 KB |
Output is correct |
16 |
Correct |
771 ms |
25076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
360 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |