DreptMax

Time limit: 0.75s Memory limit: 64MB Input: dreptmax.in Output: dreptmax.out

Cerință

Se dă o matrice cu nn linii și mm coloane, ale cărei elemente sunt numere întregi nenegative.
Pentru fiecare celulă (i,j)(i, j) definim:

Value(i,j)=Value(i, j) = aria maximă a unui dreptunghi cu colțul stânga-sus fixat în (i,j)(i, j), astfel încât suma elementelor din dreptunghi să fie mai mică sau egală cu kk.

Se cere să se afișeze

S=i=1nj=1mValue(i,j).S = \sum_{i=1}^{n} \sum_{j=1}^{m} Value(i, j).

Date de intrare

Pe prima linie se află trei numere întregi nn, mm și kk.
Pe următoarele nn linii se află câte mm numere întregi, separate prin spații, reprezentând elementele matricei.

Date de ieșire

Pe prima linie a fișierului de ieșire dreptmax.out se va găsi un singur număr întreg, reprezentând suma cerută în enunț.

Restricții și precizări

  • 1n,m2 0001 \le n, m \le 2\ 000
  • 0k5 0000 \le k \le 5\ 000
  • 0mat[i][j]1000 \le \text{mat}[i][j] \le 100
# Punctaj Restricții
1 10 25n,m35, 0mat[i][j]100, 0k200025 \le n, m \le 35,\ 0 \le \text{mat}[i][j] \le 100,\ 0 \le k \le 2000
2 20 90n,m120, 0mat[i][j]100, 0k500090 \le n, m \le 120,\ 0 \le \text{mat}[i][j] \le 100,\ 0 \le k \le 5000
3 30 n=m=400, 0mat[i][j]100, 0k4000n = m = 400,\ 0 \le \text{mat}[i][j] \le 100,\ 0 \le k \le 4000
4 10 1n,m2000, mat[i][j]=0, k=01 \le n, m \le 2000,\ \text{mat}[i][j] = 0,\ k = 0
5 30 1n,m2000, 0mat[i][j]100, 0k<501 \le n, m \le 2000,\ 0 \le \text{mat}[i][j] \le 100,\ 0 \le k < 50

Exemplul 1

dreptmax.in

5 5 5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1

dreptmax.out

100

Exemplul 2

dreptmax.in

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

dreptmax.out

545

Log in or sign up to be able to send submissions!