#C628. Median of Two Sorted Arrays

    ID: 50022 Type: Default 1000ms 256MiB

Median of Two Sorted Arrays

Median of Two Sorted Arrays

Given two sorted arrays A and B, your task is to find the median of the combined sorted array obtained by merging them. The median is defined as the middle element when the total number of elements is odd, or the average of the two middle elements when the total number is even.

More formally, if the merged array is ( M ) with ( n ) elements, the median is defined as:
( \text{median} = M_{\lfloor n/2 \rfloor} ) if ( n ) is odd, and
( \text{median} = \frac{M_{n/2 - 1} + M_{n/2}}{2} ) if ( n ) is even.

inputFormat

The input is read from standard input and consists of three lines.
(1) The first line contains two non-negative integers ( n ) and ( m ), representing the sizes of arrays A and B respectively.
(2) The second line contains ( n ) integers in non-decreasing order, representing array A. (If ( n = 0 ), this line will be empty.)
(3) The third line contains ( m ) integers in non-decreasing order, representing array B. (If ( m = 0 ), this line will be empty.)

outputFormat

Output the median of the merged array as a floating-point number. The answer should be printed to standard output.## sample

2 1
1 3
2
2.0