Easy Binary Search 
Code
# Code
```cpp []
class Solution {
public:
    bool check(int idx, vector<int>& nums, vector<int>& v) {
        int n = nums.size();
        int m = v.size();
        vector<int> lastIdx(n, -1);
        for (int i = idx; i >= 0; i--) {
            if (lastIdx[v[i] - 1] == -1) {
                lastIdx[v[i] - 1] = i;
            }
        }
        map<int, int> mp; // time is the key and which ever index is gonna get
        // marked is the value;
        for (int i = 0; i < lastIdx.size(); i++) {
            if (lastIdx[i] == -1)
                return false;
            mp[lastIdx[i]] = i;
        }
        int count = 0;
        for (int i = 0; i <= idx; i++) {
            if (mp.find(i) == mp.end()) {
                count++;
            } else {
                count -= nums[mp[i]];
                if (count < 0)
                    return false;
            }
        }
        return true;
    }
    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& c) {
        int n = nums.size();
        int m = c.size();
        int low = 0;
        int high = m - 1;
        int ans = -1;
        while (low <= high) {
            int mid = low + (high - low) / 2;
            if (check(mid, nums, c) == true) {
                high = mid - 1;
                ans = mid + 1;
            } else {
                low = mid + 1;
            }
        }
        return ans;
    }
};
```
['Array', 'Binary Search', 'C++']