We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);intn=scanner.nextInt();if(n<1||n>20000){scanner.close();thrownewIllegalArgumentException("The number of lists must be a positive integer below 20000");}ArrayList<ArrayList<Integer>>array=newArrayList<>();for(inti=0;i<n;i++){intd=scanner.nextInt();if(d<0||d>50000){scanner.close();thrownewIllegalArgumentException("Each list must contain between 1 and 50000 numbers");}ArrayList<Integer>inner=newArrayList<>();for(intj=0;j<d;j++){intnextInt=scanner.nextInt();inner.add(nextInt);}array.add(inner);}intq=scanner.nextInt();if(q<1||q>1000){scanner.close();thrownewIllegalArgumentException("The number of queries must be between 1 and 1000");}for(inti=0;i<q;i++){intx=scanner.nextInt();inty=scanner.nextInt();if(x<1||x>n){scanner.close();thrownewIllegalArgumentException(String.format("The line used for searching cannot be greater than %d",n));}try{System.out.println(array.get(x-1).get(y-1));}catch(IndexOutOfBoundsExceptionexc){System.out.println("ERROR!");}}scanner.close();}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Arraylist
You are viewing a single comment's thread. Return to all comments →