#P2706. Chocolate Box Rescue
Chocolate Box Rescue
Chocolate Box Rescue
You are given a chocolate box divided into \(n \times m\) cells. Each cell \((i,j)\) contains \(a_{i,j}\) pieces of chocolate. However, the night before shipment, mice attacked the box and some cells got robbed (and have holes). Your task is to cut out a rectangular sub-box that contains no attacked (robbed) cells and has the maximum total chocolates.
The attacked cells are marked with \(-1\) in the input, and they cannot be part of the selected rectangle. If no valid rectangle exists, output \(0\).
inputFormat
The first line contains two integers \(n\) and \(m\), representing the number of rows and columns respectively. The next \(n\) lines each contain \(m\) integers. Each integer \(a_{i,j}\) represents the number of chocolates at cell \((i,j)\). A value of \(-1\) indicates the cell was attacked by mice and is not available.
outputFormat
Output a single integer — the maximum total number of chocolates that can be obtained from a rectangular sub-box that does not include any attacked cells. If no such sub-box exists, output \(0\).
sample
3 3
1 2 3
4 5 6
7 8 9
45