• + 0 comments

    Hi All, I have a question. the code below passes almost all the tests except two, in which the number of given elements (n) is 20000. I suppose the code generates runtime error due to large number of elements, I just don't understand why.

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
        int n,d;
        List<List<Integer>> arr = new ArrayList<List<Integer>>();
        Scanner key = new Scanner(System.in);
        n = key.nextInt();
        for (int i=0;i<n;i++) {
            d = key.nextInt();
            for (int j=0;j<d;j++) {
                List<Integer> arr2 = new ArrayList<Integer>();
                arr.add(arr2);
                arr.get(i).add(key.nextInt());
            }
        }
        n = key.nextInt();
        for (int i=0;i<n;i++) {
            int x = key.nextInt()-1;
            int y = key.nextInt()-1;
            try {
            System.out.println(arr.get(x).get(y));
            }
            catch (Exception e)
            {
                System.out.println("ERROR!");
            }
        }
    }
    

    }