Balance
InterviewTime limit1sMemory limit512 MB
Given an N x N matrix A, find the entrywise-minimal balanced matrix B (satisfying the additive rectangle condition) with B[i][j] >= A[i][j], and report its sum.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, Math, Matrix
- Solved
- No attempts yet
Problem
A matrix of size is called balanced if for all .
You are given a matrix of size . Output a matrix of the same size such that is balanced and for all . In addition, the sum of the entries of must be as small as possible.
Input
The first line contains an integer , the number of rows and columns of the matrix ().
Each of the following lines contains integers. Together they describe the matrix . It is guaranteed that for all .
Output
On the first line, print the sum of the entries of the balanced matrix you found. On the next lines, print the balanced matrix in the same format as the input.
Any matrix satisfying the conditions described in the statement is accepted. The values of the output matrix are not constrained in any way (in particular, they may exceed ).