PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000049. Trung vị của tất cả trung vị đoạn con (Median of Medians)
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 tất cả trung vị đoạn con (Median of Medians)
Median of Medians
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
For each nonempty contiguous subarray, compute its median. Collect the medians of all subarrays, and find the median of that collection. For a sequence of length , the median is its -th smallest element (1-based): for even length, use the right middle.
Input
The first line is . The second line contains integers .
Output
Print the final median.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
3
10 30 20
Output
30
Explanation
The six medians are 10,30,20,30,30,20. Sorting yields 10,20,20,30,30,30; the right-middle (fourth) element is 30.