Chess
InterviewTime limit1sMemory limit128 MB
Each row holds at most one rook, so take the largest value in every row with a positive maximum and add them.
Problem
Pawełek is still learning chess and is currently working on how the rook moves. So far he only knows that a rook moves horizontally: it can move to any cell in its own row, and to no other cell.
Using this knowledge, Pawełek invented his own game. He draws a square board and writes one integer in each cell. Then he places some rooks on the board, trying to make the sum of the numbers on the occupied cells as large as possible. He may place any number of rooks (he can always borrow more if he needs them), and if he places none, the sum is taken to be .
To keep the game from being too easy, he follows one rule: no two rooks may occupy the same cell, and no two rooks may attack each other. By the rules he knows, a rook attacks along its own row, so in effect no two rooks may be placed in the same row.
Given the size of the board and the numbers written in its cells, find the largest sum Pawełek can obtain by placing rooks according to these rules.
Input
The first line contains an integer (), the height and width of the board. Each of the next lines describes one row of the board, in order: the -th of these lines contains integers separated by spaces, the values written in the cells of the -th row. Each integer is between and , inclusive.
Output
Print a single integer: the maximum sum Pawełek can obtain.