-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSolution.java
More file actions
35 lines (28 loc) · 969 Bytes
/
Copy pathSolution.java
File metadata and controls
35 lines (28 loc) · 969 Bytes
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
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
List<ArrayList<Integer>> lines = new ArrayList<>();
for (int i = 0; i < n; i++) {
int d = scanner.nextInt();
ArrayList<Integer> line = new ArrayList<>();
for (int j = 0; j < d; j++) {
line.add(scanner.nextInt());
}
lines.add(line);
}
int q = scanner.nextInt();
for (int i = 0; i < q; i++) {
int x = scanner.nextInt() - 1;
int y = scanner.nextInt() - 1;
if (x >= 0 && x < lines.size()
&& y >= 0 && y < lines.get(x).size()) {
System.out.println(lines.get(x).get(y));
} else {
System.out.println("ERROR!");
}
}
scanner.close();
}
}