easy cpp solution to understand
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    bool findSafeWalk(vector<vector<int>>& grid, int health) {
        int n = grid.size();
        int m = grid[0].size();
        int nrow[] = {0, 0, 1, -1};
        int ncol[] = {1, -1, 0, 0};

        priority_queue<pair<int, pair<int, int>>>pq;
        vector<vector<int>>path(n, vector<int>(m, 0));
        pq.push({(health - grid[0][0]), {0, 0}});
        path[0][0] = health - grid[0][0];

        while(!pq.empty()){
            auto ele = pq.top();
            pq.pop();
            int cost = ele.first;
            int row = ele.second.first;
            int col = ele.second.second;

            if(row == n-1 && col == m-1){
                return true;
            }

            for(int i = 0;i < 4;i++){
                int newrow = row + nrow[i];
                int newcol = col + ncol[i];

                if(newrow >= 0 && newrow < n && newcol >= 0 && newcol < m){
                    if(path[newrow][newcol] < cost - grid[newrow][newcol]){
                        path[newrow][newcol] = cost - grid[newrow][newcol];
                        pq.push({path[newrow][newcol], {newrow, newcol}});
                    }
                }
            }
        }

        return false;
    }
};
```
['C++']