Straightforward Java Solution
\nclass RLEIterator {\n    \n    int pos = 1;\n    int num = 0;\n    int val = 0;\n    int[] A;\n\n    public RLEIterator(int[] A) {\n        this.A = A;\n    }
```\nclass RLEIterator {\n    \n    int pos = 1;\n    int num = 0;\n    int val = 0;\n    int[] A;\n\n    public RLEIterator(int[] A) {\n        this.A = A;\n    }\n    \n    public int next(int n) {\n        while (pos < A.length && num < n) {\n            num += A[pos - 1];\n            val = A[pos];\n            pos += 2;\n        }\n        num -= n; // substract the n before return anything\n        if (pos > A.length && num < 0) {\n            return -1;\n        }\n        return val;\n    }\n}\n\n```
[]