You are given a matrix ‘M’ having dimensions ‘WIDTH x ‘HEIGHT’ and provided with an integer ‘N’. The matrix ‘M’ can take only binary values, i.e., 0 and 1. Your task is to find the “maximum number of ones” that the matrix ‘M’ can have such that every square sub-matrix of M of dimensions ‘N’ x ‘N’ has no more than ‘MAXONES’ ones.
Input Format:
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the T test cases follow.
The first and only line of each test case contains four positive integers, ‘WIDTH’, ‘HEIGHT’, ‘N’, and ‘MAXONES’, as described in the problem statement.
Output Format:
For each test case, print a single line containing a single integer denoting the maximum number of ones that the matrix M can have.
The output for each test case will be printed in a separate line.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= ‘T’ <= 10
1 <= ‘WIDHT’, ‘HEIGHT’ <= 1000
1 <= ‘N’ <= WIDHT, HEIGHT
0 <= ‘MAXONES’ <= N * N
Where ‘T’ is the number of test cases, ‘WIDHT’ x ‘HEIGHT’ is the dimension of the matrix, ‘N’ * ‘N’ is the dimension of the square sub-matrix, and ‘MAXONES’ is the maximum number of ones a square sub-matrix can have.
Time Limit: 1sec.