Problem Description: Darsh recently found an new rectangular circuit board that he would like to recycle. That has R rows and C columns of squares. Each square of the circuit board has a very thinness, measured in millimetres. The square in the r-th row and c-th column has thinness Mr,c. A circuit board is beautiful if in each row, the difference between the thinnest square and the least thin square is no greater than L. Since the original circuit board might not be beautiful, Darsh would like to find a beautiful subcircuit board. This board can be obtained by choosing an axis-aligned subrectangle from the original board and taking the squares in that subrectangle. Darsh would like your help in finding the number of squares in the largest beautiful subrectangle of his original board. Constraints: 1 ≤ T ≤ 50. 1 ≤ R ≤ 205. 1 ≤ C ≤ 205. 0 ≤ Mi, j ≤ 10^3 for all i, j. 0 ≤ L ≤ 10^3. Input Format: The first line of the input gives the number of test cases, T. T test cases follow. Each test case begins with one line containing three integers R, C and L, the number of rows, the number of columns, and the maximum difference in thinness allowed in each row.
C Program

#include<stdio.h>
#include<stdbool.h>

int A[309][309];              // mandatory
bool ok[309][309][309];      // mandatory

int max(int a,int b){return a>b?a:b;}

int main(){
    int T;
    scanf("%d",&T);

    while(T--){
        int R,C,L;
        scanf("%d%d%d",&R,&C,&L);

        int i,j,k;

        for(i=0;i<R;i++)
            for(j=0;j<C;j++)
                scanf("%d",&A[i][j]);

        // Step 1: precompute valid segments per row
        for(i=0;i<R;i++){
            for(j=0;j<C;j++){
                int mn=A[i][j], mx=A[i][j];
                for(k=j;k<C;k++){
                    if(A[i][k]<mn) mn=A[i][k];
                    if(A[i][k]>mx) mx=A[i][k];
                    ok[i][j][k] = (mx - mn <= L);
                }
            }
        }

        int ans = 0;

        // Step 2: fix column range
        for(j=0;j<C;j++){
            for(k=j;k<C;k++){

                int cnt = 0;

                // Step 3: count consecutive valid rows
                for(i=0;i<R;i++){
                    if(ok[i][j][k]){
                        cnt++;
                        ans = max(ans, cnt * (k - j + 1));
                    } else {
                        cnt = 0;
                    }
                }
            }
        }

        printf("%d\n",ans);
    }

    return 0;
}