Partitioning a matrix to minimize the maximum cost