one of the best application of minHeap
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```\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n    bool Is_Possible(vector<int>& nums, vector<int>& changeIndices, int end) {\n        int count = 0;\n        int n = nums.size();\n        vector<int> last(n, -1);\n\n        // Adjust the \'last\' vector with the indices till the \'end\'\n        for (int i = 0; i <= end; i++) {\n            if (changeIndices[i] < n) {\n                last[changeIndices[i]] = i;\n            }\n        }\n\n        int power = 0;\n        for (int i = 0; i <= end; i++) {\n            int idx = changeIndices[i];\n            if (idx < n && i == last[idx]) {\n                if (power < nums[idx]) return false;\n                power -= nums[idx];\n                count++;\n            } else {\n                power++;\n            }\n        }\n        return count == n;\n    }\n\n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n        int n = nums.size();\n        int m = changeIndices.size();\n        int ans = -1;\n\n        // Adjusting changeIndices to be zero-indexed\n        for (int i = 0; i < m; i++) {\n            if (changeIndices[i] > 0) {\n                changeIndices[i]--;\n            }\n        }\n\n        int start = 0;\n        int end = m - 1;\n\n        while (start <= end) {\n            int mid = (start + end) / 2;\n            if (Is_Possible(nums, changeIndices, mid)) {\n                ans = mid;\n                end = mid - 1;\n            } else {\n                start = mid + 1;\n            }\n        }\n        return  ans==-1?-1: ans + 1;\n    }\n};\n\n```
['C++']