-
Notifications
You must be signed in to change notification settings - Fork 2
/
백인찬.java
111 lines (105 loc) · 3.53 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.io.*;
import java.util.*;
public class Main {
static int N, M;
static PriorityQueue<PriorityQueue<Integer>> pqs;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
pqs = new PriorityQueue<>(Comparator.comparingInt(PriorityQueue::peek));
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
int p = Integer.parseInt(st.nextToken());
int q = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder());
for (int j = 0; j < p; j++) {
pq.add(Integer.parseInt(st.nextToken()));
}
if(pq.size() >= q) {
for (int j = 0; j < q - 1; j++) {
pq.remove();
}
}
else {
pq.clear();
}
if(pq.size() == 0) {
pq.add(0);
}
pqs.add(pq);
}
int total = 0;
for (int i = 0; i < N; i++) {
int a = pqs.remove().peek();
if(a == 0) a = 1;
if(M >= a && a <= 36) {
M -= a;
total++;
}
}
bw.write(total + "\n");
bw.flush();
bw.close();
}
}
//
//// 배열 버전
//import java.io.*;
//import java.util.*;
//
//public class Main {
// static int N, M;
// static PriorityQueue[] pqs;
// public static void main(String[] args) throws IOException {
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
// StringBuilder sb = new StringBuilder();
// StringTokenizer st = new StringTokenizer(br.readLine());
//
// N = Integer.parseInt(st.nextToken());
// M = Integer.parseInt(st.nextToken());
//
// pqs = new PriorityQueue[N];
// for (int i = 0; i < N; i++) {
// pqs[i] = new PriorityQueue<Integer>(Comparator.reverseOrder());
// }
//
// for (int i = 0; i < N; i++) {
// st = new StringTokenizer(br.readLine());
// int p = Integer.parseInt(st.nextToken());
// int q = Integer.parseInt(st.nextToken());
// st = new StringTokenizer(br.readLine());
// for (int j = 0; j < p; j++) {
// pqs[i].add(Integer.parseInt(st.nextToken()));
// }
// if(pqs[i].size() >= q) {
// for (int j = 0; j < q - 1; j++) {
// pqs[i].remove();
// }
// }
// else {
// pqs[i].clear();
// }
// if(pqs[i].size() == 0) {
// pqs[i].add(0);
// }
// }
// Arrays.sort(pqs, Comparator.comparingInt(o -> (int) o.peek()));
// int total = 0;
// for (int i = 0; i < N; i++) {
// int a = (int) pqs[i].peek();
// if(a == 0) a = 1;
// if(M >= a && a <= 36) {
// M -= a;
// total++;
// }
// }
// bw.write(total + "\n");
// bw.flush();
// bw.close();
// }
//}