C++ || EASY LAST VISIT
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```\nclass Solution {\npublic:\n    long long check(vector<int>& a, vector<int>& c,long long h,long long need){\n    vector<int> lvis(a.size(),-1);\n    long long op=0;\n    for(int i=h;i>=0;i--){\n        if(lvis[c[i]-1]==-1){\n            lvis[c[i]-1]=0;\n            op+=a[c[i]-1];\n            need--;\n        }else {\n            if(op>0) {\n                op--;\n                need--;\n            }\n        }\n    } \n    if(need==0){ return 1; }\n    return 0;\n    }\n    int earliestSecondToMarkIndices(vector<int>& a, vector<int>& c) { \n    long long need=0,kp=0;\n    for(int i=0;i<a.size();i++){\n         need+=a[i]+1;\n    }\n    long long l=0,r=c.size()-1,ans=1e9;\n    while(l<=r){\n       long long mid=(l+r)/2;\n        if(check(a,c,mid,need)){\n            r=mid-1;\n            ans=min(ans,mid);\n        }else{\n            l=mid+1;\n        }\n    }\n    if(ans==1e9)  return -1;\n    \n    return ans+1;\n    }\n};\n```
['C++']