public static void Solve() { var(H, W, K, V) = Scanner.Scan <int, int, long, long>(); var cum = new CumulativeSum2D(H, W); for (var i = 0; i < H; i++) { var A = Scanner.ScanEnumerable <long>().ToArray(); for (var j = 0; j < W; j++) { cum.Set(i, j, A[j]); } } var answer = 0L; for (var i = 0; i < H; i++) { for (var j = 0; j < W; j++) { for (var ii = i + 1; ii <= H; ii++) { for (var jj = j + 1; jj <= W; jj++) { var a = (ii - i) * (jj - j); var v = cum.Sum(i, j, ii, jj) + a * K; if (v <= V) { answer = Math.Max(answer, a); } } } } } Console.WriteLine(answer); }
public static void Solve() { var(H, W) = Scanner.Scan <int, int>(); var G = new int[H][].Select(_ => Scanner.ScanEnumerable <int>().ToArray()).ToArray(); var cum2d = new CumulativeSum2D(H, W); for (var i = 0; i < H; i++) { for (var j = 0; j < W; j++) { cum2d.Set(i, j, G[i][j] * ((i + j) % 2 == 0 ? 1 : -1)); } } var answer = 0L; for (var h1 = 1; h1 <= H; h1++) { for (var h2 = 0; h2 < h1; h2++) { for (var w1 = 1; w1 <= W; w1++) { for (var w2 = 0; w2 < w1; w2++) { if (cum2d.Sum(h1, w1, h2, w2) == 0) { answer = Math.Max(answer, (h1 - h2) * (w1 - w2)); } } } } } Console.WriteLine(answer); }