c++ solution
\nclass Solution {\npublic:\n    int maxScore(vector<vector<int>>& grid) {\n        int n=grid.size();\n        int m=grid[0].size();\n        int ans=-1e8;\n  
```\nclass Solution {\npublic:\n    int maxScore(vector<vector<int>>& grid) {\n        int n=grid.size();\n        int m=grid[0].size();\n        int ans=-1e8;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                int prevMin=1e9;\n                if(i==0&&j==0) continue;\n                if(i>0) prevMin=min(prevMin,grid[i-1][j]);\n                if(j>0) prevMin=min(prevMin,grid[i][j-1]);\n                ans=max(ans,grid[i][j]-prevMin);\n                grid[i][j]=min(grid[i][j],prevMin);\n            }\n        }\n        return ans;\n    }\n};\n```
['C', 'C++']