#C4461. Garden Plant Maximization

    ID: 48002 Type: Default 1000ms 256MiB

Garden Plant Maximization

Garden Plant Maximization

You are given a garden represented as a grid with n rows and m columns. Each cell of the garden contains either a plant (denoted by 1) or is empty (denoted by 0). In order to remove conflicts, at most one plant can be kept in any row or any column. Your task is to compute the maximum number of plants that can remain in the garden if you remove some plants, and the minimum number of removals required to achieve that configuration.

Formally, let R be the number of rows that initially contain at least one plant, and C be the number of columns that initially contain at least one plant. Then the maximum number of plants you can keep is

P=min(R,C),P=\min(R, C),

and the minimum number of removals is the difference between the initial number of plants and P.

Note: The input is read from stdin and the output is printed to stdout.

inputFormat

The first line contains two integers n and m representing the number of rows and columns of the garden respectively. This is followed by n lines, each containing m space-separated integers (each either 0 or 1) representing the state of each cell in the garden.

Example:

3 4
1 0 0 1
0 1 0 0
0 0 1 0

outputFormat

Output two integers separated by a space: the maximum possible number of plants remaining in the garden with no row or column conflicts, and the minimum number of removals needed to achieve that configuration.

Example:

3 1
## sample
3 4
1 0 0 1
0 1 0 0
0 0 1 0
3 1