Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class QueryPrinting {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter n: ");
- int n = sc.nextInt();
- ArrayList<Integer>[] inpData = new ArrayList[n];
- int[] numEle = new int[n];
- for (int i = 0; i < n; i++) {
- inpData[i] = new ArrayList<Integer>();
- numEle[i] = sc.nextInt();
- for (int j = 0; j < numEle[i]; j++) {
- inpData[i].add(sc.nextInt());
- }
- }
- int nQuery = sc.nextInt();
- int[][] query = new int[nQuery][2];
- for (int i = 0; i < nQuery; i++) {
- for (int j = 0; j < 2; j++) {
- query[i][j] = sc.nextInt() - 1;
- }
- }
- for (int i = 0; i < nQuery; i++) {
- if (query[i][0] < n && query[i][1] < numEle[query[i][0]]) {
- System.out.println(inpData[query[i][0]].get(query[i][1]));
- } else {
- System.out.println("-1");
- }
- }
- sc.close();
- }
- }
Add Comment
Please, Sign In to add comment