-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
41 lines (37 loc) · 1.36 KB
/
Solution.java
File metadata and controls
41 lines (37 loc) · 1.36 KB
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
38
39
40
41
// https://www.hackerrank.com/challenges/java-arraylist/problem
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
ArrayList<ArrayList<Integer>> arr = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
while (n-- > 0) {
int line_n = scanner.nextInt();
ArrayList<Integer> line = new ArrayList<>();
while (line_n-- > 0) {
line.add(scanner.nextInt());
}
arr.add(line);
}
int nq = scanner.nextInt();
ArrayList<ArrayList<Integer>> queries = new ArrayList<>();
while (nq-- > 0) {
int x = scanner.nextInt();
int y = scanner.nextInt();
ArrayList<Integer> tmp = new ArrayList<>();
tmp.add(x); tmp.add(y);
queries.add(tmp);
}
for (ArrayList<Integer> query : queries) {
int xi = query.get(0), yi = query.get(1);
ArrayList<Integer> a = arr.get(xi - 1);
if (a.size() >= yi) {
System.out.println(a.get(yi - 1));
} else {
System.out.println("ERROR!");
}
}
}
}