import java.util.*;
public class cipele
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), m = sc.nextInt();
int a[] = new int[n];
int b[] = new int[m];
for(int i = 0; i < n; i++)
{
a[i] = sc.nextInt();
}
for(int i = 0; i < m; i++)
{
b[i] = sc.nextInt();
}
Arrays.sort(a);
Arrays.sort(b);
int l = 0, r = 1000000000;
int ans = r;
while(l <= r)
{
int mid = (l + r) / 2;
int pos = 0;
boolean condition = true;
for(int i = 0; i < Math.min(n, m); i++)
{
if(pos == Math.max(m, n))
{
condition = false;
break;
}
if(n == Math.min(n, m))
{
if(Math.abs(b[pos] - a[i]) <= mid)
{
pos++;
continue;
}
}
if(m == Math.min(n, m))
{
if(Math.abs(a[pos] - b[i]) <= mid)
{
pos++;
continue;
}
}
i--;
pos++;
}
if(condition == true)
{
r = mid - 1;
ans = mid;
}
else
{
l = mid + 1;
}
}
System.out.println(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
821 ms |
21048 KB |
Output is correct |
2 |
Execution timed out |
1088 ms |
26600 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
925 ms |
26592 KB |
Output is correct |
2 |
Correct |
867 ms |
26732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
398 ms |
15248 KB |
Output is correct |
2 |
Correct |
582 ms |
22804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
497 ms |
22300 KB |
Output is correct |
2 |
Correct |
522 ms |
21344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
671 ms |
22248 KB |
Output is correct |
2 |
Correct |
618 ms |
22448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
513 ms |
21288 KB |
Output is correct |
2 |
Correct |
567 ms |
22940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
573 ms |
21548 KB |
Output is correct |
2 |
Correct |
584 ms |
21712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
917 ms |
25952 KB |
Output is correct |
2 |
Execution timed out |
1070 ms |
25604 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
915 ms |
27348 KB |
Output is correct |
2 |
Correct |
832 ms |
20284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
893 ms |
26940 KB |
Output is correct |
2 |
Execution timed out |
1048 ms |
26380 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |