-
Notifications
You must be signed in to change notification settings - Fork 2
/
황정훈.java
50 lines (44 loc) · 1.56 KB
/
황정훈.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
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.*;
import java.util.*;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static StringBuilder sb = new StringBuilder();
static StringTokenizer st;
static int N, M;
static PriorityQueue<Integer> pq = new PriorityQueue();
public static void main(String[] args) throws Exception {
st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
int P = Integer.parseInt(st.nextToken());
int L = Integer.parseInt(st.nextToken());
if (P<L) {
pq.add(1);
br.readLine();
}
else{
Integer[] points = new Integer[P];
st = new StringTokenizer(br.readLine());
for (int j = 0; j < P; j++) {
points[j] = Integer.parseInt(st.nextToken());
}
Arrays.sort(points, Collections.reverseOrder());
pq.add(points[L-1]);
}
}
for (int i = 0; i < N; i++) {
M -= pq.poll();
if (M<0){
sb.append(i);
break;
}
}
bw.write(sb.length()>0 ? sb.toString() : String.valueOf(N)+"\n");
bw.flush();
bw.close();
br.close();
}
}