Using Priority_Queue || C++
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```cpp []\nclass Solution {\npublic:\n    int minTimeToReach(vector<vector<int>>&grid) {\n        int n=grid.size();\n        int m=grid[0].size();\n        vector<int>dr={-1,0,1,0};\n        vector<int>dc={0,1,0,-1};\n       priority_queue<pair<int,pair<int,pair<int,int>>>,vector<pair<int,pair<int,pair<int,int>>>>,greater<pair<int,pair<int,pair<int,int>>>>>q;\n        vector<vector<int>>dist(n,vector<int>(m,INT_MAX));\n        q.push({0,{0,{0,0}}});\n        while(!q.empty()){\n            int d=q.top().first;\n            int adj=q.top().second.first;\n            int r=q.top().second.second.first;\n            int c=q.top().second.second.second;\n            q.pop();\n            for(int i=0;i<4;i++){\n                int rr=r+dr[i];\n                int cc=c+dc[i];\n                if(rr>=0 && rr<n && cc>=0 && cc<m){\n                    int maxi=max(d,grid[rr][cc]);\n                    if(adj==0){\n                        if(1+maxi<dist[rr][cc]){\n                            dist[rr][cc]=1+maxi;\n                            q.push({dist[rr][cc],{1,{rr,cc}}});\n                        }\n                    }\n                    else{\n                        if(2+maxi<dist[rr][cc]){\n                            dist[rr][cc]=2+maxi;\n                            q.push({dist[rr][cc],{0,{rr,cc}}});\n                        }\n                    }\n                }\n                \n            }\n\n        }\n         \n        return dist[n-1][m-1];\n        \n    }\n};\n```
['C++']