#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3qplfh5 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
void print(){
cout<<"\n";
}
template<class te,class ...ti>
void print(const te&v, const ti&...nv) {
cout<<v;
if(sizeof...(nv)){
cout<<" ";
print(nv...);
}
}
using pii=pair<int,int>;
using vi=vector<int>;
using vll=vector<long long>;
const int _n=7e5+11;
void slv(){
int n,m;
cin>>n>>m;
vi a(n),b(m);
rep(i,n){
cin>>a[i];
}
rep(i,m){
cin>>b[i];
}
if(n>m){
swap(n,m);
swap(a,b);
}
sort(all(a));
multiset<int> omst;
rep(i,m){
omst.insert(b[i]);
}
auto f=[&](int len)->bool{
multiset<int> mst=omst;
rep(i,n){
int x=a[i];
auto it=mst.lower_bound(x-len);
if(it==mst.end() or abs(*it-x)>len){
return false;
}
mst.erase(it);
}
return true;
};
int l=0,r=1e9,c=-1;
while(l<=r){
int m=(l+r)/2;
if(f(m)){
c=m;
r=m-1;
}else{
l=m+1;
}
}
print(c);
}
int main(){
_3qplfh5;
int t=1;
// cin>>t;
rep(cs,t)
slv();
//
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
11948 KB |
Output is correct |
2 |
Correct |
369 ms |
12288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
387 ms |
12216 KB |
Output is correct |
2 |
Correct |
377 ms |
12228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
588 KB |
Output is correct |
2 |
Correct |
13 ms |
904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
828 KB |
Output is correct |
2 |
Correct |
14 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
864 KB |
Output is correct |
2 |
Correct |
13 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
844 KB |
Output is correct |
2 |
Correct |
13 ms |
920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
872 KB |
Output is correct |
2 |
Correct |
18 ms |
924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
580 ms |
11500 KB |
Output is correct |
2 |
Correct |
257 ms |
7384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
388 ms |
11360 KB |
Output is correct |
2 |
Correct |
189 ms |
10088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
407 ms |
11032 KB |
Output is correct |
2 |
Correct |
270 ms |
10440 KB |
Output is correct |