-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Solution.java
37 lines (32 loc) · 1.06 KB
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// github.com/RodneyShag
import java.util.Scanner;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
/* Save numbers in 2-D ArrayList */
ArrayList<ArrayList<Integer>> lists = new ArrayList();
for (int row = 0; row < n; row++) {
int d = scan.nextInt();
ArrayList<Integer> list = new ArrayList();
for (int col = 0; col < d; col++) {
list.add(scan.nextInt());
}
lists.add(list);
}
/* Answer the queries */
int q = scan.nextInt();
for (int i = 0; i < q; i++) {
int x = scan.nextInt();
int y = scan.nextInt();
ArrayList<Integer> list = lists.get(x-1);
if (y <= list.size()) {
System.out.println(list.get(y-1));
} else {
System.out.println("ERROR!");
}
}
scan.close();
}
}