#C11644. Minimum Sector Sum
Minimum Sector Sum
Minimum Sector Sum
You are given a square grid containing integer power values assigned to each sector. Your task is to determine the sum of power values in the most vulnerable sector, defined as the contiguous square subgrid with the smallest sum.
Formally, let the grid be an \( N \times N \) matrix \( A \). A contiguous square subgrid is defined by its top-left corner \( (i, j) \) and a size \( k \) (with \( 1 \le k \le N \)) such that the subgrid consists of the elements \( A_{p,q} \) with \( i \le p \le i+k-1 \) and \( j \le q \le j+k-1 \). The sum of this subgrid is \( \sum_{p=i}^{i+k-1} \sum_{q=j}^{j+k-1} A_{p,q} \). Your goal is to find the minimum such sum among all possible contiguous square subgrids.
Note: The input grid is guaranteed to be a square grid.
inputFormat
The first line contains a single integer \( N \) representing the size of the square grid. Each of the following \( N \) lines contains \( N \) space-separated integers representing the power values of the sectors.
outputFormat
Output a single integer, the minimum sum of any contiguous square subgrid within the grid.
## sample3
1 2 3
4 5 6
7 8 9
1