#P9457. [入门赛 #14] 魔法少女扶苏 (Hard Version)
[入门赛 #14] 魔法少女扶苏 (Hard Version)
Problem Description
You are given a numeric matrix with rows and columns. The number in row and column is called .
Fusu can cast magic any number of times. Each time she casts the magic, every number in the matrix is decreased by .
Now Fusu wants to know: at least how many times does she need to cast the magic so that there exist at least positions in the matrix such that is greater than or equal to the sum of the elements in its row and its column.
Formally, you need to compute the minimum number of magic casts such that after casting, there exist at least positions satisfying $a_{x, y} \geq \sum \limits _{i = 1}^n a_{i,y} + \sum \limits _{i = 1}^m a_{x,i}$.
Input Format
The first line contains three integers, representing the number of rows , the number of columns , and the required number of positions .
Then follow lines, each containing integers. The -th integer in the -th line represents the initial value of .
Output Format
Output one line with one integer, representing the answer.
2 3 1
1 2 3
4 5 6
3
Hint
Sample 1 Explanation
After casting the magic times, the matrix becomes
Then $a_{1,1} = -2 > (-1) + (-3) = \sum\limits_{i =1}^n a_{i,1} + \sum\limits_{i = 1}^m a_{1, i}$.
Constraints
- For of the testdata, it is guaranteed that , , .
Hint
Please use a reasonable input method to avoid TLE.
Translated by ChatGPT 5