c++ solution
\nclass Solution {\npublic:\n    int minTimeToReach(vector<vector<int>>& mat) {\n        int n=mat.size();\n        int m=mat[0].size();\n        priority_queue
```\nclass Solution {\npublic:\n    int minTimeToReach(vector<vector<int>>& mat) {\n        int n=mat.size();\n        int m=mat[0].size();\n        priority_queue<tuple<long long,long long,int>,vector<tuple<long long,long long,int>>,greater<tuple<long long,long long,int>>>pq;\n        vector<pair<int,int>>d={{-1,0},{1,0},{0,1},{0,-1}};\n        vector<vector<long long>>dis(n,vector<long long>(m,1e18));\n        pq.push({0,0,0});\n        dis[0][0]=0;\n        vector<vector<int>>vis(n,vector<int>(m,0));\n        long long time=0;\n        while(pq.size()){\n            auto [cost,xy,type]=pq.top();\n            pq.pop();\n            int x=xy/m;\n            int y=xy%m;\n            if(vis[x][y]) continue;\n            vis[x][y]=1;\n            for(auto &it:d){\n                int nx=x+it.first;\n                int ny=y+it.second;\n                if(nx>=0&&ny>=0&&nx<n&&ny<m){\n                    long long alter =(type==0)?1:2;\n                    time=cost+alter;\n                    long long actualTime=max(time,1ll*mat[nx][ny]+alter);\n                    if(actualTime<dis[nx][ny]){\n                        dis[nx][ny]=actualTime;\n                        pq.push({dis[nx][ny],nx*m+ny,type^1});\n                    }\n                }\n            }\n        }\n        return dis[n-1][m-1];\n    }\n};\n```
['C', 'C++']