[Python3] Binary Search
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```\nclass Solution:\n    def earliestSecondToMarkIndices(self, nums: List[int], changeIndices: List[int]) -> int:\n        n = len(nums)\n        m = len(changeIndices)\n\n        # decreased indices for convenience\n        for i in range(m):\n            changeIndices[i] -= 1\n        \n        def isGood(pos):\n            used = [False]*n\n            # points - how many points are reserved on the left side\n            # for already used numbers\n            points = 0\n            for i in range(pos, -1, -1):\n                if used[changeIndices[i]]:\n                    points = max(0, points-1)\n                    continue\n                num = changeIndices[i]\n                used[num] = True\n                if nums[num] > (i-points):\n                    return False\n                points += nums[num]\n            # all numbers should be marked\n            return used.count(False) == 0\n        \n        # binary search\n        lo = 0\n        hi = m - 1\n        \n        best = -1\n        while lo <= hi:\n            mid = (lo+hi) // 2\n            \n            if isGood(mid):\n                best = mid+1\n                hi = mid-1\n            else:\n                lo = mid+1\n        \n        return best    \n```
['Python3']