#579. 「Nowcoder多校 2019 Day3」Planting Trees
「Nowcoder多校 2019 Day3」Planting Trees
当前没有测试数据。
题目描述
The semester is finally over and the summer holiday is coming. However, as part of your university's graduation requirement, you have to take part in some social service during the holiday. Eventually, you decided to join a volunteer group which will plant trees in a mountain.
To simplify the problem, let's represent the mountain where trees are to be planted with an grid. Let's number the rows to from top to bottom, and number the columns to from left to right. The elevation of the cell in the -th row and -th column is denoted by . Your leader decides that trees should be planted in a rectangular area within the mountain and that the maximum difference in elevation among the cells in that rectangle should not exceed M. In other words, if the coordinates of the top-left and the bottom-right corners of the rectangle are and , then the condition must hold for . Please help your leader calculate the maximum possible number of cells in such a rectangle so that he'll know how many trees will be planted.
输入格式
The input contains multiple cases. The first line of the input contains a single integer , the number of cases. For each case, the first line of the input contains two integers N and M . The following N lines each contain N integers, where the -th integer in the -th line denotes . It is guaranteed that the sum of over all cases does not exceed .
输出格式
For each case, print a single integer, the maximum number of cells in a valid rectangle.
样例
样例输入 1
2
2 0
1 2
2 1
3 1
1 3 2
2 3 1
3 2 1
样例输出 1
1
4