#abc203d. D - Pond
D - Pond
Score : points
问题描述
AtCoder 公园的土地是一个 的网格,东西方向为行,南北方向为列。从西边数第 列、从北边数第 行的正方形高度记为 。
作为公园经理的高桥决定在这个公园内建造一个占据 个方格的正方形池塘。
为了实现这个目标,他希望在公园内完全包含 个方格的正方形区域内选择一个部分,使得该区域中正方形高度的中位数尽可能低。请找出这样一个区域内正方形高度的中位数。
这里,一个 区域内正方形高度的中位数是指,在该区域内的 个正方形中,按照高度从高到低排列后,第 高的正方形的高度,其中 表示不超过 的最大整数。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
The land of a park AtCoder is an grid with east-west rows and north-south columns. The height of the square at the -th row from the north and -th column from the west is given as .
Takahashi, the manager, has decided to build a square pond occupying squares in this park.
To do this, he wants to choose a square section of squares completely within the park whose median of the heights of the squares is the lowest. Find the median of the heights of the squares in such a section.
Here, the median of the heights of the squares in a section is the height of the -th highest square among the squares in the section, where is the greatest integer not exceeding .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 2
1 7 0
5 8 11
10 4 2
Sample Output 1
4
Let denote the square at the -th row from the north and -th column from the west. We have four candidates for the section occupied by the pond: $\{(1,1),(1,2),(2,1),(2,2)\}, \{(1,2),(1,3),(2,2),(2,3)\}, \{(2,1),(2,2),(3,1),(3,2)\}, \{(2,2),(2,3),(3,2),(3,3)\}$.
When , since , the median of the heights of the squares in a section is the height of the -rd highest square, which is , , , for the candidates above, respectively. We should print the lowest of these: .
Sample Input 2
3 3
1 2 3
4 5 6
7 8 9
Sample Output 2
5
update @ 2024/3/10 09:15:59