-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLELEMON.java
More file actions
56 lines (34 loc) · 1.01 KB
/
LELEMON.java
File metadata and controls
56 lines (34 loc) · 1.01 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
class Ideone{
//https://www.codechef.com/problems/LELEMON
public static Scanner scn = new Scanner(System.in);
public static void main (String[] args) throws java.lang.Exception{
int T = scn.nextInt();
while(T-- > 0){
int N = scn.nextInt();
int M = scn.nextInt();
int[] P = new int[M];
for(int i = 0; i < M; i++)
P[i] = scn.nextInt();
//int[] rooms = new int[N][128];
ArrayList<Integer>[] rooms = new ArrayList[N];
for(int i = 0; i < N; i++){
rooms[i] = new ArrayList<Integer>();
int bottles = scn.nextInt();
for(int j = 0; j < bottles; j++)
rooms[i].add(scn.nextInt());
Collections.sort(rooms[i]);
}
long volume = 0;
for(int i = 0; i < M; i++){
int room_no = P[i];
if(rooms[room_no].size() > 0)
volume += rooms[room_no].remove(rooms[room_no].size() - 1);
}
System.out.println(volume);
}
}
}