#C2353. Median of Two Sorted Arrays

    ID: 45660 Type: Default 1000ms 256MiB

Median of Two Sorted Arrays

Median of Two Sorted Arrays

You are given two sorted arrays of integers. Your task is to find the median of the combined array formed by merging the two arrays. The median is defined as follows:

If the total number of elements is odd, the median is the middle element. If the total number of elements is even, the median is the average of the two middle elements.

In mathematical form, if the combined sorted array is \( A = [a_1, a_2, \dots, a_n] \) then:

  • \( n \) odd: median = \( a_{(n+1)/2} \)
  • \( n \) even: median = \( \frac{a_{n/2} + a_{n/2+1}}{2} \)

Round the result to five decimal places.

inputFormat

The input is given via standard input (stdin) and consists of three lines:

  1. The first line contains two integers \( n \) and \( m \) representing the sizes of the first and second sorted arrays, respectively.
  2. The second line contains \( n \) integers separated by spaces, denoting the first sorted array.
  3. The third line contains \( m \) integers separated by spaces, denoting the second sorted array.

outputFormat

Output the median of the two sorted arrays as a floating point number rounded to five decimal places. The output should be sent to standard output (stdout).

## sample
3 2
1 3 5
2 4
3.00000