This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
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... |
# | 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... |