Circuit Board
Time limit15sMemory limit1024 MB
Find the largest axis-aligned subrectangle where each row's max minus min is at most K, and report its number of squares.
- Level
Medium6 of 10
- Topics
- Sliding window, Two pointers, Array
- Solved
- No attempts yet
Problem
Arsh recently found an old rectangular circuit board that he would like to recycle. The board has rows and columns of squares. Each square has a thickness in millimetres. The square in row and column has thickness .
A circuit board is good if in each row, the difference between the thickest square and the thinnest square is at most . The original board might not be good, so Arsh wants to find a good subcircuit board. A subcircuit board is an axis-aligned subrectangle of the original board.
Find the number of squares in the largest good subrectangle.
Input
The first line contains , the number of test cases. Each test case begins with a line containing , , and . Then lines follow, each with integers. The -th integer on the -th line is .
Output
For each test case, output one line Case #x: y, where is the test case number starting from 1, and is the maximum number of squares in a good subrectangle.
Constraints
.
.
.
for all .