Simple O(LogN) C++ solution using map
\nmap<long, long> cache;\n    //storing end index\n    long currIdx;\n\n    RLEIterator(vector<int>& A) \n    {\n        long end = 0;\n        for(int i=0; i<A
```\nmap<long, long> cache;\n    //storing end index\n    long currIdx;\n\n    RLEIterator(vector<int>& A) \n    {\n        long end = 0;\n        for(int i=0; i<A.size(); i=i+2)\n        {\n            if(A[i]==0)\n                continue;\n            end += A[i];\n            cache[end] = A[i+1];\n        }\n        currIdx = 0;\n    }\n    \n    int next(int n) \n    {\n        currIdx += n;\n        auto itr = cache.lower_bound(currIdx);\n        if(itr->first < currIdx)\n            return -1;\n        return itr->second;\n    }\n```
['C', 'C++']