#K9561. Maximum Total Magical Power

    ID: 38902 Type: Default 1000ms 256MiB

Maximum Total Magical Power

Maximum Total Magical Power

You are given an n × m grid where each row represents a tree and the elements in the row represent the magical power of fruits on that tree. Your task is to pick exactly one fruit from each tree such that the total magical power is maximized.

Note: For each tree, you should always pick the fruit with the highest magical power. The input is provided via standard input and the result should be output via standard output.

Formally, let \(A_{i,j}\) denote the magical power of the j\(-th\) fruit on tree \(i\) (1-indexed). For each row \(i\), choose one index \(j_i\) (\(1 \le j_i \le m\)) such that the sum \(\sum_{i=1}^{n}\max_{1 \le j \le m}A_{i,j}\) is maximized.

You need to output a single integer representing the maximum total magical power that can be collected.

inputFormat

The first line contains two integers \(n\) and \(m\) separated by a space, representing the number of trees (rows) and the number of fruits per tree (columns), respectively.

This is followed by \(n\) lines, each containing \(m\) integers. Each integer represents the magical power of a fruit.

Input is read from standard input.

outputFormat

Output a single integer: the maximum total magical power achievable by choosing one fruit (with the maximal power) from each tree.

Output should be written to standard output.

## sample
3 3
2 1 7
3 5 4
6 10 1
22