~/algor $ cat problems/matritsa-eng-qimmat-yol
Most valuable path
Medium
1000 ms
128 MB
65%
An integer matrix of size $n \times m$ is given. You walk from the top-left cell $(1, 1)$ to the bottom-right cell $(n, m)$, moving only right or down at each step. Find the largest possible sum of the elements of all cells on the path (the start and the finish included).
Input
The first line contains two positive integers $n$ and $m$. Each of the next $n$ lines contains $m$ integers.
Output
One integer — the largest path sum.
Note
$1 \le n, m \le 200$
$-1000 \le a_{i,j} \le 1000$
Examples
Input #1
3 3 1 3 1 1 5 1 4 2 1
Output #1
12
Input #2
2 2 -1 -5 -2 -1
Output #2
-4