PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000201. Trung vị của hai dãy đã sắp xếp (Median of Two Sorted Arrays)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Trung vị của hai dãy đã sắp xếp (Median of Two Sorted Arrays)
Median of Two Sorted Arrays
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Two integer sequences of lengths are nondecreasing. Conceptually merge them into a nondecreasing sequence of length , retaining duplicates. Its median is the middle element for odd length, or the mean of the two middle elements for even length. Find this median. Either sequence may be empty but their combined length is positive.
Input
The first line contains integers . The second contains integers and the third integers . An empty sequence has an empty corresponding line.
Output
Print the median with exactly one digit after the decimal point.
Subtasks
- Subtask 1 (20 points): ; ; for all valid indices; both sequences are nondecreasing.
- Subtask 2 (30 points): ; ; for all valid indices; both sequences are nondecreasing.
- Subtask 3 (50 points): ; ; for all valid indices; both sequences are nondecreasing.
Examples
Input
2 2
1 2
3 4
Output
2.5
Explanation
The merged sequence is . Its middle positions 2 and 3 contain 2 and 3; their mean is 2.5.