C# 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```\npublic class Solution {\n    public int EarliestSecondToMarkIndices(int[] nums, int[] changeIndices) {\n        int n = nums.Length, m = changeIndices.Length;\n        List<int>[] v = new List<int>[n];\n        \n        for (int i = 0; i < n; ++i) v[i] = new List<int>();\n        for (int i = 0; i < m; ++i) v[changeIndices[i] - 1].Add(i);\n\n        if (check(nums, v, m - 1) == false) return -1;\n\n        int left = 0, right = m - 1;\n        while (left < right) {\n            int mid = left + (right - left) / 2;\n\n            if (check(nums, v, mid)) right = mid;\n            else left = mid + 1;\n        }\n\n        return left + 1;\n    }\n\n    private bool check(int[] nums, List<int>[] v, int m) {\n        int n = nums.Length;\n        int[] data = new int[m + 1];\n\n        for (int i = 0; i < n; ++i) {\n            if (v[i].Count == 0 || v[i][0] > m) return false;\n            int left = 0, right = v[i].Count - 1;\n            while (left < right) {\n                int mid = right - (right - left) / 2;\n    \n                if (v[i][mid] <= m) left = mid;\n                else right = mid - 1;\n            }\n            data[v[i][left]] += nums[i] + 1;\n        }\n\n        long sum = 0;\n        for (int i = 0; i <= m; ++i) {\n            sum += data[i];\n            if (sum > i + 1) return false;\n        }\n\n        return true;\n    }\n}\n```
['Binary Search', 'C#']