Skip to content

Commit f2fb85f

Browse files
authored
Merge pull request #1374 from AlgorithmWithGod/JHLEE325
[20251111] BOJ / G3 / 과제 / 이준희
2 parents a5cf2ae + c2b6622 commit f2fb85f

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
static class homework implements Comparable<homework> {
8+
int deadline;
9+
int score;
10+
homework(int d, int s) {
11+
deadline = d;
12+
score = s;
13+
}
14+
@Override
15+
public int compareTo(homework o){
16+
return this.deadline - o.deadline;
17+
}
18+
}
19+
20+
public static void main(String[] args) throws IOException {
21+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
22+
int N = Integer.parseInt(br.readLine());
23+
homework[] hw = new homework[N];
24+
int duedate = 0;
25+
26+
for (int i = 0; i < N; i++) {
27+
StringTokenizer st = new StringTokenizer(br.readLine());
28+
int d = Integer.parseInt(st.nextToken());
29+
int w = Integer.parseInt(st.nextToken());
30+
hw[i] = new homework(d, w);
31+
if (d > duedate) duedate = d;
32+
}
33+
34+
Arrays.sort(hw);
35+
36+
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
37+
long result = 0;
38+
int idx = N - 1;
39+
40+
for (int day = duedate; day >= 1; day--) {
41+
while (idx >= 0 && hw[idx].deadline >= day) {
42+
pq.offer(hw[idx].score);
43+
idx--;
44+
}
45+
46+
if (!pq.isEmpty()) {
47+
result += pq.poll();
48+
}
49+
}
50+
51+
System.out.println(result);
52+
}
53+
}
54+
```

0 commit comments

Comments
 (0)