#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param grid int整型二维数组 
# @return int整型

class Solution:
    def maxValue(self , grid: List[List[int]]) -> int:
        # write code here
        R,C=len(grid),len(grid[0])
        arr=[[grid[0][0] for j in range(C)] for i in range(R)]
        for i in range(R):
            if i > 0:
                arr[i][0]=arr[i-1][0]+grid[i][0]
            for j in range(1,C):
                if i==0:
                    arr[0][j]=arr[0][j-1]+grid[0][j]
                else:
                    arr[i][j]=max(arr[i][j-1]+grid[i][j],arr[i-1][j]+grid[i][j])
        return arr[R-1][C-1]