#BS0000407. Trung vị lớn nhất (Max Median)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Trung vị lớn nhất (Max Median)
Max Median
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers , define the median of a list of length as the element at position in its nondecreasing ordering, indexed from 1. For example, has median 2. Choose a contiguous segment with and . Find the greatest possible median.
Input
The first line contains integers . The second line contains integers .
Output
Print one integer: the greatest achievable median.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
5 3
1 2 3 2 1
Output
2
Explanation
The segments of length 3 are ; of length 4, ; of length 5, the entire list. All six have median 2 after sorting.
Input
4 2
1 2 3 4
Output
3
Explanation
The segment has median 3. No segment of length at least 2 has median 4 because only one element is 4.
Input
3 2
3 1 3
Output
3
Explanation
Both length-2 segments have median 1, whereas the entire segment sorts to and has median 3.