Task
From a matrix of size , three matrices , , are constructed with the following properties:
For each cell in the matrix , where :
- ;
- ;
- is the sum of the submatrix with the top-left corner at and the bottom-right corner at from the matrix .
You are given , , and the matrices , , . You need to display a way to change exactly values in the matrix , such that the sum of the values in is minimized. Additionally, you need to display the minimum sum. You can choose to keep the element in cell in the matrix unchanged, in which case you will display of the matrix at cell .
Input data
The first line of the input file partsum.in
contains two integers, and . The next lines will contain values each, representing the values in . The following lines will contain values each, representing the values in . The next lines will contain values each, representing the values in .
Note! In the tests, there are no empty lines between the matrices , , and . They have been added only for clarification in the example!
Output data
The first lines of the output file partsum.out
will contain three values , representing that the value in cell will change to . On the -th line, the minimum sum formed will be displayed.
Note! If at least one value among or is not within the interval , the verdict will be Wrong Answer. Additionally, if at least one value is not within the interval , the verdict will be Wrong Answer.
Constraints and clarifications
- ;
- ;
- There may be multiple correct solutions, any of them will be accepted.
- If the changes do not lead to the sum of the values in being the sum displayed on the -th line, you will receive points!
- It is guaranteed that the matrices , , and originate from a matrix .
- .
- It is guaranteed that the elements of the matrix are natural numbers.
# | Points | Constraints |
---|---|---|
1 | 13 | , |
2 | 15 | |
3 | 29 | |
4 | 43 | No additional constraints |
Example 1
partsum.in
2 1
0 0
0 0
0 1
0 0
2 5
3 3
partsum.out
1 1 0
9
Explanation
The matrix from which , and are derived is:
2 3
3 3
If we change the value to in cell , the sums on row will become , and the sum of the values in becomes . This is the minimum sum that can be formed if we change at most one element.