C# | Binary Search
Code
# Code
```csharp []
public class Solution {
    public int EarliestSecondToMarkIndices(int[] nums, int[] changeIndices)
    {
        int sum = 0;
        for (int i = 0; i < nums.Length; i++)
        {
            sum += nums[i];
            if (sum >= 2000)
                return -1;
        }
        if (sum >= changeIndices.Length)
            return -1;
        int left = sum + nums.Length - 1;
        int right = changeIndices.Length;
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (IsPossible(0, mid, nums.Length, changeIndices, sum, nums))
            {
                right = mid;
            }
            else
            {
                left = mid + 1;
            }
        }
        return left < changeIndices.Length ? left + 1 : -1;
    }

    static bool IsPossible(int left, int right, int num, int[] changeIndices, int sum, int[] nums)
    {
        Dictionary<int, int> map = new();
        for (int i = right; i >= 0; i--)
        {
            if (!map.ContainsKey(changeIndices[i]))
            {
                num--;
                map.Add(changeIndices[i], i);
            }
        }
        if (num > 0) return false;
        map = map.Reverse().ToDictionary();
        int count = 0;
        foreach (var pair in map)
        {
            int temp = nums[pair.Key - 1];
            int val = pair.Value;
                count += temp;
                if (pair.Value < count)
                    return false;
                count++;
        }
        return true;
    }
}
```
['Array', 'Binary Search', 'C#']