#abc311g. G - One More Grid Task

G - One More Grid Task

Score : 575575 points

问题描述

存在一个 N×MN \times M 的网格,其中从上到下的第 ii 行、从左到右的第 jj 列有一个非负整数 Ai,jA_{i,j}

让我们选择一个矩形区域 RR。形式上,该区域按照以下方式选定:

  • 选择整数 lx,rx,ly,ryl_x, r_x, l_y, r_y 使得 1lxrxN,1lyryM1 \le l_x \le r_x \le N, 1 \le l_y \le r_y \le M
  • 然后,如果满足条件 lxirxl_x \le i \le r_xlyjryl_y \le j \le r_y,则第 (i,j)(i,j) 个格子属于区域 RR

求解 f(R)f(R) 可能的最大值,其中 f(R)=f(R) = (区域内所有格子上整数之和)×\times(区域内格子上最小的整数)。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is an N×MN \times M grid, where the square at the ii-th row from the top and jj-th column from the left has a non-negative integer Ai,jA_{i,j} written on it.
Let us choose a rectangular region RR.
Formally, the region is chosen as follows.

  • Choose integers lx,rx,ly,ryl_x, r_x, l_y, r_y such that 1lxrxN,1lyryM1 \le l_x \le r_x \le N, 1 \le l_y \le r_y \le M.
  • Then, square (i,j)(i,j) is in RR if and only if lxirxl_x \le i \le r_x and lyjryl_y \le j \le r_y.

Find the maximum possible value of f(R)=f(R) = (the sum of integers written on the squares in RR) ×\times (the smallest integer written on a square in RR).

Constraints

  • All input values are integers.
  • 1N,M3001 \le N,M \le 300
  • 1Ai,j3001 \le A_{i,j} \le 300

Input

The input is given from Standard Input in the following format:

NN MM

A1,1A_{1,1} A1,2A_{1,2} \dots A1,MA_{1,M}

A2,1A_{2,1} A2,2A_{2,2} \dots A2,MA_{2,M}

\vdots

AN,1A_{N,1} AN,2A_{N,2} \dots AN,MA_{N,M}

Output

Print the answer as an integer.

Sample Input 1

3 3
5 4 3
4 3 2
3 2 1

Sample Output 1

48

Choosing the rectangular region whose top-left corner is square (1,1)(1, 1) and whose bottom-right corner is square (2,2)(2, 2) achieves f(R)=(5+4+4+3)×min(5,4,4,3)=48f(R) = (5+4+4+3) \times \min(5,4,4,3) = 48, which is the maximum possible value.

Sample Input 2

4 5
3 1 4 1 5
9 2 6 5 3
5 8 9 7 9
3 2 3 8 4

Sample Output 2

231

Sample Input 3

6 6
1 300 300 300 300 300
300 1 300 300 300 300
300 300 1 300 300 300
300 300 300 1 300 300
300 300 300 300 1 300
300 300 300 300 300 1

Sample Output 3

810000

update @ 2024/3/10 08:51:59