C++ || TOO EASY || CLEAN SHORT CODE
\n# Code\n\nclass Solution {\npublic:\n    int earliestSecondToMarkIndices(vector<int>& a, vector<int>& id) {\n        int n=a.size();\n        int s=id.size();
\n# Code\n```\nclass Solution {\npublic:\n    int earliestSecondToMarkIndices(vector<int>& a, vector<int>& id) {\n        int n=a.size();\n        int s=id.size();\n        int l=1,r=s,ans=-1;\n        while(l<=r)\n        {\n            int m=(l+r)/2;\n            map<int,int> p;\n            for(int i=1;i<=m;i++)\n            p[id[i-1]]=i;\n            bool b=1;\n            int e=0;\n            for(int i=1;i<=m;i++)\n            {\n                e++;\n                if(p[id[i-1]]==i)\n                {\n                 if(e-1<a[id[i-1]-1]) b=0;\n                 else e=e-1-a[id[i-1]-1];\n                 }\n            }\n            if(p.size()!=n) b=0;\n            if(b)\n            {\n                r=m-1;\n                ans=m;\n            }\n            else l=m+1;\n        }\n        return ans;\n    }\n};\n```
['C++']