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>
#include<math.h>
#include<stdlib.h>
using namespace std;
int l[100010],r[100010];
int main(){
int n,m,i,j,k;
cin >> n >> m;
for(i=1;i<=n;i++)
cin >> l[i];
for(i=1;i<=m;i++)
cin >> r[i];
sort(l,l+n);
sort(r,r+m);
if(n==m) {
k=0;
for(i=1;i<=n;i++) {
if(abs(l[i]-r[i])>k)
k=abs(l[i]-r[i]);
}
}
else if(n>m) {
i=1;
int x=i+m;
if(i+m>n)
x=n;
while(x<n && l[x]<r[0])
x++;
i=x-m;
k=-1;
for(;i<=n-m+1;i++)
{
int y = 0;
for(j=1;j<=m;j++){
if(abs(l[j+i-1]-r[j])>y)
y=abs(l[j+i-1]-r[j]);
}
if(y<k || k==-1)
k=y;
if(l[i]>r[m])
break;
}
}
else
{
i=1;
int x=i+n;
if(i+n>m)
x=m;
while(x<m && l[x]<r[0])
x++;
i=x-n;
k=-1;
for(;i<=m-n+1;i++)
{
int y = 0;
for(j=1;j<=n;j++){
if(abs(l[j]-r[j+i-1])>y)
y=abs(l[j]-r[i+j-1]);
}
if(y<k || k==-1)
k=y;
if(r[i]>l[n])
break;
}
}
cout << k << 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... |