Simple C++ Solution Using Binary Search
\nclass Solution {\npublic:\n    bool isPossible(vector<int>& nums, vector<int>& changeIndices, int seconds)\n    {\n        int n = nums.size();\n        vecto
```\nclass Solution {\npublic:\n    bool isPossible(vector<int>& nums, vector<int>& changeIndices, int seconds)\n    {\n        int n = nums.size();\n        vector<int> last(n + 1, -1);\n        \n        for(int i = 0; i < seconds; i++)\n            last[changeIndices[i] - 1] = i;\n        \n        int marked = 0;\n        int operations = 0;\n        \n        for(int i = 0; i < seconds; i++)\n        {\n            if(i == last[changeIndices[i] - 1])\n            {\n                if(operations < nums[changeIndices[i] - 1])\n                    return false;\n                else\n                {\n                    operations -= nums[changeIndices[i] - 1];\n                    marked++;\n                }\n            }\n            else\n                operations++;\n        }\n        \n        return (marked == n);\n    }\n    \n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n        \n        int m = changeIndices.size();\n        int low = 0, high = m + 1;\n        \n        while(low < high)\n        {\n            int mid = (low + high) / 2;\n            \n            if(isPossible(nums, changeIndices, mid))\n                high = mid;\n            else\n                low = mid + 1;\n        }\n        \n        if(high == m + 1)\n            return -1;\n        \n        return high;\n    }\n};\n```
['Binary Search', 'C', 'Binary Tree', 'C++']