DP
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```csharp []\npublic class Solution {\n    public int MaxScore(IList<IList<int>> grid) {\n        int rows = grid.Count, cols = grid[0].Count;\n        if (rows == 0 || cols == 0)\n            return 0;\n        int[,] dp = new int[rows, cols];\n        int res = int.MinValue;\n        dp[0, 0] = grid[0][0];\n\n        for(int j = 1; j < cols; j++)\n        {\n            res = Math.Max(res, grid[0][j] - dp[0,j-1]);\n            dp[0,j] = Math.Min(grid[0][j], dp[0,j-1]);\n        }\n\n        for(int i = 1; i < rows; i++)\n        {\n            res = Math.Max(res, grid[i][0] - dp[i-1, 0]);\n            dp[i, 0] = Math.Min(grid[i][0], dp[i-1, 0]);\n        }\n\n        for(int i = 1; i < rows; i++)\n        for(int j = 1; j < cols; j++)\n        {\n            int pre = Math.Min(dp[i-1, j-1], Math.Min(dp[i-1, j], dp[i, j-1]));\n            res = Math.Max(grid[i][j]-pre, res);\n            dp[i,j] = Math.Min(pre, grid[i][j]);\n        }\n\n        return res;\n    }\n}\n```
['C#']