Untitled
unknown
plain_text
a year ago
1.0 kB
12
Indexable
import java.util.Scanner;
public class MaximumMatrix {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt(); // Number of test cases
for (int t = 0; t < T; t++) {
int n = scanner.nextInt(); // Number of rows
int m = scanner.nextInt(); // Number of columns
int K = scanner.nextInt(); // Maximum value for each cell
int L = scanner.nextInt(); // Maximum sum of any pair of adjacent cells
System.out.println(maximumSum(n, m, K, L));
}
scanner.close();
}
private static int maximumSum(int n, int m, int K, int L) {
// Considering the constraints L >= 2 by setting the max allowable value in the matrix
int maxAllowableValue = Math.min(K, L / 2);
// Once the max allowable value is determined, fill the matrix with this value
int sum = maxAllowableValue * n * m;
return sum;
}
}
Editor is loading...
Leave a Comment