#K6651. Median of Merged Sorted Lists
Median of Merged Sorted Lists
Median of Merged Sorted Lists
You are given two sorted lists of integers, each of length \(N\). Your task is to merge these two lists into a single sorted list and then find the median of the merged list.
The median is defined as follows: if the merged list has an even number of elements (which will always be the case here since the merged list has \(2N\) elements), then the median is the average of the two middle elements. Specifically, let \(M = 2N\); then the median is given by \[ \text{median} = \frac{a_{\frac{M}{2}} + a_{\frac{M}{2}+1}}{2} \] where the list is 1-indexed. (For zero-indexed arrays, this corresponds to \(\frac{a_{M/2 - 1} + a_{M/2}}{2}\).)
You need to implement a complete program that reads the input from standard input and outputs the result to standard output.
inputFormat
The input is read from standard input and has the following format:
- The first line contains a single integer \(N\), representing the length of both sorted lists.
- The second line contains \(N\) space-separated integers representing the first sorted list (
list_A
). - The third line contains \(N\) space-separated integers representing the second sorted list (
list_B
).
outputFormat
Output a single line containing the median of the merged sorted list as a floating point value.
## sample3
1 3 5
2 4 6
3.5