TreeMap, Java O(log(n)) time next function 
\nclass RLEIterator {\n    TreeMap<Long, Integer> map = new TreeMap<>();\n    long cur = 0;\n    public RLEIterator(int[] A) {\n        long count = 0;\n       
```\nclass RLEIterator {\n    TreeMap<Long, Integer> map = new TreeMap<>();\n    long cur = 0;\n    public RLEIterator(int[] A) {\n        long count = 0;\n        for (int i = 0; i < A.length - 1; i += 2) {\n            if (A[i] == 0) continue;\n            count += A[i];\n            map.put(count, A[i + 1]);\n        }\n    }\n    \n    public int next(int n) {\n        cur += n;\n        Long val = map.ceilingKey(cur);\n        if (val == null) return -1;\n        return map.get(val);\n    }\n}\n```
[]