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 <iostream>
#include <algorithm>
using namespace std;
int N,M;
long long A[100000],B[100000],K,T,F[100000],k,R;
long long Q(int q,int w)
{
if (q==N) {
R=0;
for (int i=0;i<k;i++) R=max(R,F[i]);
T=min(T,R);
} else {
for (int i=w;i<M;i++) {
K=A[q]-B[i];
if (K<0) K*=-1;
F[k]=K;
k++;
Q(q+1,i+1);
k--;
}
}
return 0;
}
int main()
{
cin.tie(0); ios_base::sync_with_stdio(0);
cin>>N>>M;
for (int i=0;i<N;i++) cin>>A[i];
for (int i=0;i<M;i++) cin>>B[i];
sort(A,A+N);
sort(B,B+M);
if (N==M) {
for (int i=0;i<N;i++) {
K=A[i]-B[i];
if (K<0) K*=-1;
T=max(K,T);
}
cout<<T;
} else {
T=10000000000000;
if (M<N) for (int i=0;i<N;i++) swap(A[i],B[i]);
Q(0,0);
cout<<T;
}
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... |