binary search, 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:Solution(){ios::sync_with_stdio(false);}\n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n        int n=nums.size(),m=changeIndices.size(),left = 0,right = m, r=-1;\n        while(left<=right) {\n            int test = (left+right)/2;\n            if(feasible(nums,changeIndices,n,m,test)) {\n               r=test;\n               right= test-1;\n            }\n            else left = test+1;\n        }\n        return r;\n    }\n\n    bool feasible(vector<int>& nums, vector<int>& changeIndices,int n, int m, int test) {\n       vector<bool> marked(n,false);\n       long long markedCount=0, borrow=0;\n       for(int i=test-1;i>=0;--i) {\n         int toMark= changeIndices[i]-1;\n         if(marked[toMark]) {\n            borrow=max(borrow-1,(long long)0);\n            continue;\n          }\n        \n         borrow+= nums[toMark];\n         marked[toMark] = true;\n         markedCount++;\n       }\n\n       return borrow<=0 && markedCount==n;\n    }\n};\n```
['C++']