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;
typedef long long ll;
#define endl '\n'
void solve(){
int n,m;
cin>>n>>m;
vector <int> v1(n);
vector <int> v2(m);
for(auto &i:v1) cin>>i;
for(auto &i:v2) cin>>i;
sort(v1.begin(),v1.end());
sort(v2.begin(),v2.end());
if(n<m){
ll ANS = 1e18;
for(int i=0;i<m-(n-1);i++){
ll cnt = 0;
ll ans = 0;
for(int j=i;j<n+i;j++){
ans = max((ll)abs(v2[j]-v1[cnt++]),ans);
}
ANS = min(ANS,ans);
}
cout<<ANS<<endl;
}
else {
ll ANS = 1e18;
for(int i=0;i<n-(m-1);i++){
ll cnt = 0;
ll ans = 0;
for(int j=i;j<m+i;j++){
ans = max((ll)abs(v1[j]-v2[cnt++]),ans);
}
ANS = min(ANS,ans);
}
cout<<ANS<<endl;
}
}
int main()
{
int t=1;
// cin>>t;
while(t--){
solve();
}
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... |