Skip to content

Commit c545872

Browse files
authored
Merge pull request #355 from AlgorithmWithGod/suyeun84
[20250614] BOJ / G3 / 순회강연 / 김수연
2 parents 073aea2 + 87ec0fc commit c545872

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class boj2109 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int N = nextInt();
14+
int[][] arr = new int[N][2];
15+
int[] store = new int[10001];
16+
int answer = 0;
17+
for (int i = 0; i < N; i++) {
18+
nextLine();
19+
arr[i][0] = nextInt();
20+
arr[i][1] = nextInt();
21+
}
22+
Arrays.sort(arr, (o1, o2) -> {
23+
return o2[0] - o1[0];
24+
});
25+
for (int i = 0; i < N; i++) {
26+
int cost = arr[i][0];
27+
int day = arr[i][1];
28+
for (int j = day; j >= 1; j--) {
29+
if (store[j] < cost) {
30+
store[j] = cost;
31+
break;
32+
}
33+
}
34+
}
35+
for (int i = 0; i < 10001; i++) answer += store[i];
36+
System.out.println(answer);
37+
}
38+
}
39+
```

0 commit comments

Comments
 (0)