Java Solution
\nclass RLEIterator {\n    int[] A;\n    int idx;\n    public RLEIterator(int[] A) {\n      this.A=A;\n      idx=0;\n    }\n    \n    public int next(int n) {\n
```\nclass RLEIterator {\n    int[] A;\n    int idx;\n    public RLEIterator(int[] A) {\n      this.A=A;\n      idx=0;\n    }\n    \n    public int next(int n) {\n        \n       while(idx<A.length && n>A[idx]) {\n           n=n-A[idx];\n           idx+=2;\n       }\n        if(idx>=A.length){\n            return -1;\n        }\n        A[idx]=A[idx]-n;\n        return A[idx+1];\n    }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * RLEIterator obj = new RLEIterator(A);\n * int param_1 = obj.next(n);\n */\n ```
[]