#P6883. [COCI 2016/2017 #3] Kroničan
[COCI 2016/2017 #3] Kroničan
Problem Description
Mislav has glass cups, numbered from to . Each cup contains some water. You need to make it so that only cups contain water by pouring water (pouring the water from one cup into another).
It is known that pouring the water from cup into cup costs . Mislav wants to know the minimum total cost needed so that after pouring, only (or fewer) cups contain water.
Input Format
The first line contains two positive integers, .
The next lines each contain non-negative integers . The number in row , column means the cost to pour water from cup to cup . It is guaranteed that is always .
Output Format
Output the minimum total cost Mislav needs to pay to achieve the goal.
3 3
0 1 1
1 0 1
1 1 0
0
3 2
0 1 1
1 0 1
1 1 0
1
5 2
0 5 4 3 2
7 0 4 4 4
3 3 0 1 2
4 3 1 0 5
4 5 5 5 0
5
Hint
Explanation for Sample 1
Mislav does not need to pour any water. The total cost is .
Explanation for Sample 2
Mislav needs to pour the water from any one cup into any other cup, so that only two cups contain water. The total cost is .
Explanation for Sample 3
Mislav can pour water from cup into cup , then pour the water in cup into cup , and finally pour the water in cup into cup . The total cost is .
Constraints
For of the testdata, .
For of the testdata, .
Notes
Translated from COCI2016-2017 CONTEST #3 T3 Kroničan。
Translated by ChatGPT 5