File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments