#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 |
1 |
Correct |
90 ms |
1144 KB |
Output is correct |
2 |
Incorrect |
140 ms |
1324 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
121 ms |
1324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1324 KB |
Output is correct |
2 |
Incorrect |
12 ms |
1324 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
1324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
1324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
1324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
1324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1085 ms |
1324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1092 ms |
1324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |