PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000211. Ao có trung vị độ cao nhỏ nhất (Pond)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ao có trung vị độ cao nhỏ nhất (Pond)
Pond
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given an grid of heights , select a contiguous square entirely inside the grid. Sort its heights in nondecreasing order; the median is the element of rank (1-based), i.e. the lower middle element when the count is even. Find the minimum median among all such squares.
Input
The first line contains . The next lines each contain integers .
Output
Print the minimum median as one integer.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; .
Example 1
Input
3 2
1 7 0
5 8 11
10 4 2
Output
4
Explanation
The four 2×2 squares have lower medians 5, 7, 5, 4, so the minimum is 4.
Example 2
Input
3 3
1 2 3
4 5 6
7 8 9
Output
5
Explanation
There is only one square; the fifth element is 5.