#K78297. Find Median of Two Sorted Arrays
Find Median of Two Sorted Arrays
Find Median of Two Sorted Arrays
You are given two sorted arrays of integers. Your task is to find the median of the combined arrays. The median of a list of numbers is defined \(\text{median} = \begin{cases} A_{\frac{n+1}{2}} & \text{if } n \text{ is odd}\\ \frac{A_{\frac{n}{2}} + A_{\frac{n}{2}+1}}{2} & \text{if } n \text{ is even} \end{cases}\), where \(A\) is the sorted merged list of the two arrays.
If both arrays are empty, the median is defined to be 0.0. You should read two lines from standard input; the first line contains the first sorted array and the second line contains the second sorted array. Each line contains zero or more integers separated by spaces. If a line is empty, it represents an empty array.
inputFormat
The input consists of two lines:
- The first line contains a space-separated list of integers forming the first sorted array (or is empty if the array is empty).
- The second line contains a space-separated list of integers forming the second sorted array (or is empty if the array is empty).
outputFormat
Output a single number representing the median of the combined arrays. The result should be printed to standard output as a floating-point number.
## sample1 2 3
4 5 6 7
4.0