diff --git "a/JHLEE325/202511/11 BOJ G3 \352\263\274\354\240\234.md" "b/JHLEE325/202511/11 BOJ G3 \352\263\274\354\240\234.md" new file mode 100644 index 00000000..9a42b8aa --- /dev/null +++ "b/JHLEE325/202511/11 BOJ G3 \352\263\274\354\240\234.md" @@ -0,0 +1,54 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static class homework implements Comparable { + int deadline; + int score; + homework(int d, int s) { + deadline = d; + score = s; + } + @Override + public int compareTo(homework o){ + return this.deadline - o.deadline; + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + homework[] hw = new homework[N]; + int duedate = 0; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int d = Integer.parseInt(st.nextToken()); + int w = Integer.parseInt(st.nextToken()); + hw[i] = new homework(d, w); + if (d > duedate) duedate = d; + } + + Arrays.sort(hw); + + PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); + long result = 0; + int idx = N - 1; + + for (int day = duedate; day >= 1; day--) { + while (idx >= 0 && hw[idx].deadline >= day) { + pq.offer(hw[idx].score); + idx--; + } + + if (!pq.isEmpty()) { + result += pq.poll(); + } + } + + System.out.println(result); + } +} +```