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;
#define int long long
#define pb push_back
const int mod=1e9+7;
int a[5005],b[5005],n,m;
int dp[5005][5005];
int fun(int idx,int idx2)
{
if(idx2==m)
{
return 0;
}
if(idx==n)
return 1e15;
int &ret=dp[idx][idx2];
if(~ret)
return ret;
ret=1e15;
ret=max(abs(a[idx]-b[idx2]),fun(idx+1,idx2+1));
ret=min(ret,fun(idx+1,idx2));
return ret;
}
signed main()
{
memset(dp,-1,sizeof dp);
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
cin>>b[i];
}
if(n<m)
{
for(int i=0;i<m;i++)
{
swap(a[i],b[i]);
}
swap(n,m);
}
sort(a,a+n);
sort(b,b+m);
cout<<fun(0,0)<<endl;
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... |