#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ins insert
#define pb push_back
#define int long long int
#define pii pair<int, int>
#define endl '\n'
#define drop(x) cout<<(x)<<endl; return;
#define all(x) x.begin(),x.end()
#define hash z0hashp
#define div z0dvp
const int mod = 1e9 +7, sze = 5e5 + 23, inf = LLONG_MAX, P = 1453;
void opt1z(){
/*
obvss:
n,m : n<m, (degilse swaple arrayleri)
a nin en boyugu ile b nin balacasi mentiqsizdi?
2 39 41 45
39 42 46
*/
int n,m;
cin>>n>>m;
vector<int> arr(n);
vector<int> brr(m);
for(int i=0;i<n;i++){
cin>>arr[i];
}
for(int i=0;i<m;i++){
cin>>brr[i];
}
if(n>m){
swap(n,m);
swap(arr,brr);
}
sort(all(brr),greater<int>());
// for(auto v:lst){
// cout<<v<<" ";
// }
// cout<<endl;
sort(all(arr));
int ans=inf;
int l =0;
int r= 1e9;
while(l<=r){
vector<int> lst;
for(auto v:brr){
lst.pb(v);
}
int mid = (l+r)/2;
// cout<<mid<<endl;
bool flag=true;
int mg =0;
for(auto v:arr){
if(mg>mid){
break;
}
while(!lst.empty() && abs(lst.back() - v)>mid){
lst.pop_back();
}
if(lst.empty()){
flag=false;break;
}
mg=max(mg,abs(lst.back()-v));
lst.pop_back();
}
if(flag && mg<=mid){
ans=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
drop(ans);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
// cin>>tt;
while(tt--){
opt1z();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
5472 KB |
Output is correct |
2 |
Correct |
46 ms |
5632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
5744 KB |
Output is correct |
2 |
Correct |
47 ms |
5688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
5020 KB |
Output is correct |
2 |
Correct |
27 ms |
3352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
5424 KB |
Output is correct |
2 |
Correct |
33 ms |
4552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
4956 KB |
Output is correct |
2 |
Correct |
43 ms |
5068 KB |
Output is correct |