COCI '15 Contest 3 #6 Domino
View as PDFMirko received an  table for his birthday, where a non-negative integer is written in each field of the table. Unfortunately, the written numbers are too large for Mirko's taste, so he will place 
 dominoes on top of the table that will cover the fields that are too large.
More precisely, Mirko places the dominoes according to the following rules:
- each domino covers two fields of the table that are adjacent in a row or in a column,
 - the dominoes do not overlap (but can touch),
 - the sum of all visible (uncovered) fields needs to be as small as possible.
 
It is your task to determine the required minimal sum of visible fields. The test data will be such that it will always be possible to place  dominoes without overlapping.
Input Specification
The first line of input contains the integers  
, the dimensions of the table, and 
 
, the number of dominoes. Each of the following 
 lines contains 
 integers from the interval 
. These 
 numbers describe Mirko's table.
In test cases worth 70% of points, it will hold .
Output Specification
The first and only line of output must contain the minimal sum of visible fields after covering the table with dominoes.
Sample Input 1
3 1
2 7 6
9 5 1
4 3 8
Sample Output 1
31
Explanation for Sample Output 1
We place the domino so it covers fields with numbers  and 
.
Sample Input 2
4 2
1 2 4 0
4 0 5 4
0 3 5 1
1 0 4 1
Sample Output 2
17
Explanation for Sample Output 2
We place the dominoes so they cover fields  and 
 in the third column.
Comments