Golang Binary Search : 3ms
\npackage main\n\nimport "sort"\n\nvar lastIndexes [2e3 + 1]int\n\nfunc earliestSecondToMarkIndices(nums []int, changeIndices []int) int {\n\tm := len(changeInd
```\npackage main\n\nimport "sort"\n\nvar lastIndexes [2e3 + 1]int\n\nfunc earliestSecondToMarkIndices(nums []int, changeIndices []int) int {\n\tm := len(changeIndices)\n\n\tans := sort.Search(m+1, func(seconds int) bool {\n\t\treturn ok(seconds, nums, changeIndices)\n\t})\n\n\tif ans == m+1 {\n\t\treturn -1\n\t}\n\n\treturn ans\n}\n\nfunc ok(seconds int, nums []int, indices []int) bool {\n\tfor i := 0; i < seconds; i++ {\n\t\tlastIndexes[indices[i]-1] = i\n\t}\n\n\tavailableDecrements := 0\n\tunique := 0\n\n\tfor i := 0; i < seconds; i++ {\n\t\tindex := indices[i] - 1\n\t\tif lastIndexes[index] == i {\n\t\t\tunique++\n\t\t\tavailableDecrements -= nums[index]\n\t\t\tif availableDecrements < 0 {\n\t\t\t\treturn false\n\t\t\t}\n\t\t} else {\n\t\t\tavailableDecrements++\n\t\t}\n\t}\n\n\treturn unique == len(nums)\n}\n\n```
['Go']