Nộp bài | Các bài nộp | Làm tốt nhất | Về danh sách bài |
MEDIANTAB - Trung vị trên bảng số |
Cities in Alberta tend to be laid out as rectangular grids of blocks. Blocks are labeled with coordinates 0 to R-1 from north to south and 0 to C-1 from west to east.
The quality of living in each particular block has been ranked by a distinct number, called quality rank, between 1 and R*C, where 1 is the best and R*C is the worst.
The city planning department wishes to identify a rectangular set of blocks with dimensions H from north to south and W from west to east, such that the median quality rank among all blocks in the rectangle is the best.
H and W are odd numbers not exceeding R and C respectively. The median quality rank among an odd number of quality ranks is defined to be the quality rank m in the set such that the number of quality ranks better than m equals the number of quality ranks worse than m.
Input Format
The first line of input will contain the four integers R C H W, where R and C represent the total size of the city, and H and W represent the dimensions of the set of blocks.
The next R lines each contain C integers, denoting an array Q where Q[a][b] is the quality rank for the block labeled a from north to south and b from west to east.
Output Format
A single integer, the best (numerically smallest) possible median quality rank of an H by W rectangle of blocks.
Example
Input:
5 5 3 3
5 11 12 16 25
17 18 2 7 10
4 23 20 3 1
24 21 19 14 9
6 22 8 13 15
Output:
9
Limit:
Subtask 1: Assume R and C do not exceed 30.
Subtask 2: Assume R and C do not exceed 100.
Subtask 3: Assume R and C do not exceed 300.
Subtask 4: Assume R and C do not exceed 1 000.
Được gửi lên bởi: | noname00.pas |
Ngày: | 2017-11-27 |
Thời gian chạy: | 0.100s-1s |
Giới hạn mã nguồn: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Ngôn ngữ cho phép: | C-CLANG C CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG C99 JAVA PAS-FPC PYTHON PYTHON3 |
Nguồn bài: | Bài tập Ôn HN 01/2017 (Thầy Đỗ Đức Đông) |