#C5443. Maximum Flowers Collection

    ID: 49093 Type: Default 1000ms 256MiB

Maximum Flowers Collection

Maximum Flowers Collection

Leia loves flowers and she wants to collect as many as possible. You are given an ( n \times m ) grid where each cell contains a certain number of flowers. Leia starts from the top-left corner ((1,1)) and wants to reach the bottom-right corner ((n,m)). At each cell, she can only move either right or down. Your task is to compute the maximum number of flowers she can collect along her path.

Formally, let ( grid[i][j] ) be the number of flowers at cell ((i,j)). You must find a path from ( (1,1) ) to ( (n,m) ) such that the sum of the values along the path is maximized, where you can only move right or down.

inputFormat

The first line contains two integers ( n ) and ( m ) separated by a space, representing the number of rows and columns of the grid respectively. The following ( n ) lines each contain ( m ) integers, where the ( j )-th integer in the ( i )-th line represents ( grid[i][j] ), the number of flowers at that cell.

outputFormat

Output a single integer, the maximum number of flowers Leia can collect on her way from the top-left to the bottom-right corner.## sample

3 3
1 3 1
1 5 1
4 2 1
12