시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
3 초 | 512 MB | 4 | 4 | 4 | 100.000% |
You are given an \(n \times m\) matrix \(A\) with integer elements and a positive integer \(k\).
For a given cell \((x_0, y_0)\) of matrix \(A\), we define the following sets of cells as \(k\)-triangles with center \((x_0, y_0)\):
For a given \(k\)-triangle \(T\), we define its cost \(f(T) = \sum_{(x,y) \in T}{A_{x,y}}\).
Your task is to find the maximum possible total cost of any two non-intersecting \(k\)-triangles. Formally, you have to find \(\max_{P \cup Q = \emptyset}{f(P) + f(Q)}\) where \(P\) and \(Q\) are some \(k\)-triangles.
The first line contains three space-separated integers \(n\), \(m\), \(k\) (\(1 \le n, m, k \le 1500\)).
Each of the next \(n\) lines contains \(m\) space-separated integers; the \(i\)-th line contains integers \(A_{i,1}, A_{i,2}, \dots , A_{i,m}\) (\(−10^9 \le A_{i,j} \le 10^9\)).
It is guaranteed that there is at least one way to choose two non-intersecting \(k\)-triangles in the matrix.
Print a single integer: the maximum possible sum of costs of two non-intersecting \(k\)-triangles.
3 4 2 0 1 0 0 0 1 1 1 0 0 1 1
6
4 5 3 -5 -7 4 5 -3 -7 -5 8 0 -7 4 6 2 6 5 7 3 1 -7 7
39
In the second example, the answer is made up of two k-triangles of type \(T_1\) with centers at \((4, 1)\) and \((3, 3)\).