simple greedy solution ,no need to use binary search  BEATS 99% solution
Intuition\nsab kuch hindi me likha h  padlo\n\n# Approach\n1)sum me total sum store h\n\n2)possible ans start time se pehle nhi hoga (kyu ki sab ko decrement ka
# Intuition\nsab kuch hindi me likha h  padlo\n\n# Approach\n1)sum me total sum store h\n\n2)possible ans start time se pehle nhi hoga (kyu ki sab ko decrement karna h 1 se + mark karn ka time )\n\n  to hamara ans start se m take hi possible hoga varna -1\n\n3) unordered set se hum ye pata kar rahe ki sare elements(indexes)\nek ek baar to aa gye h na ... kyu jab tak nhi ayge tab tak ans possible nhi h \n\n4)jese ji set ka size ==n hoga or i>=start hoga to hum us index k liye apna ans check karege ...\nagar possible hoa to ans return kar dege (ispos function ko deko vo check karega ki ans possible he ya nhi)\n=>hum last index of occur ke basis per mark kar rahe he (ager is se pos nahi hoga to kese bhi nahi hoga)\n\n5)** imp point yaha 1 based indexing use hui he to thoda uska dhyan rakhe\n\n# Complexity\n\ntime complexity=>M*N (at most)\n\n- Space complexity:\n\n\n# Code\n```\nclass Solution {\npublic:\n    \n    bool ispos(vector<int> &v,int n,vector<int> &nums){\n        map<int,int> mp;\n        for(int i=0;i<n;i++){          // marking order ka set\n           mp[v[i]]=i;   \n        }\n        \n        long long prev=0;\n        for(auto &i:mp){\n            int ind=i.second;\n            if(prev+nums[ind]+1>v[ind])\n                return 0;\n            prev+=nums[ind]+1;\n        }\n        return 1;\n    }\n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& arr) {\n        \n        long long sum=0;\n        int n=nums.size();\n        for(int i=0;i<nums.size();i++){\n            sum+=nums[i];\n        }\n        long long start=sum+n;\n        \n        int m=arr.size();\n        \n      \n         vector<int> v(n,-1);\n        unordered_set<int> s;\n        for(int i=0;i<m;i++){\n         s.insert(arr[i]);\n           v[arr[i]-1]=i+1;                    // marking time ka vector\n            if(s.size()==n && i+1>=start){\n                if(ispos(v,n,nums))\n                    return i+1;\n            }\n        }\n        return -1;\n    }\n};\n```
['C++']