Skip to content

Commit 8bda657

Browse files
authored
[20250615] BOJ / G2 / 보석 도둑 / 이강현
1 parent 40672de commit 8bda657

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static int N,K;
10+
static int[][] jewelryInfo;
11+
static TreeMap<Integer,Integer> backpack; //중복되는 가방 구분을 위한 맵
12+
static long sum;
13+
14+
15+
public static void main(String[] args) throws IOException {
16+
st = new StringTokenizer(br.readLine());
17+
N = Integer.parseInt(st.nextToken());
18+
K = Integer.parseInt(st.nextToken());
19+
jewelryInfo = new int[N][2]; // 0이면 무게, 1이면 가격
20+
backpack = new TreeMap<>();
21+
for (int i = 0; i < N; i++) {
22+
st = new StringTokenizer(br.readLine());
23+
jewelryInfo[i][0] = Integer.parseInt(st.nextToken());
24+
jewelryInfo[i][1] = Integer.parseInt(st.nextToken());
25+
}
26+
for (int i = 0; i < K; i++) {
27+
int capacity = Integer.parseInt(br.readLine());
28+
backpack.put(capacity,backpack.getOrDefault(capacity,0)+1);
29+
}
30+
Arrays.sort(jewelryInfo,(a,b) -> b[1]-a[1]);
31+
32+
sum = 0;
33+
for (int i = 0; i < N; i++) {
34+
Integer cur = backpack.ceilingKey(jewelryInfo[i][0]);
35+
if(cur != null){
36+
sum += jewelryInfo[i][1];
37+
backpack.put(cur,backpack.get(cur)-1);
38+
if(backpack.get(cur)==0){
39+
backpack.remove(cur);
40+
}
41+
}
42+
}
43+
bw.write(sum+"");
44+
bw.close();
45+
}
46+
}
47+
```

0 commit comments

Comments
 (0)