-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
47 lines (38 loc) · 1.12 KB
/
Main.java
File metadata and controls
47 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.ArrayList;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
ArrayList<Problem> problems = new ArrayList<>();
for(int i=0; i<N; i++){
int deadLine = sc.nextInt();
int cupRamen = sc.nextInt();
problems.add(new Problem(deadLine, cupRamen));
}
Collections.sort(problems, (c1, c2) -> Integer.compare(c1.deadLine, c2.deadLine));
PriorityQueue<Integer> pq = new PriorityQueue<>();
for(Problem p : problems){
pq.add(p.cupRamen);
if(p.deadLine < pq.size()){
pq.poll();
}
}
int sum = 0;
while(!pq.isEmpty()){
sum += pq.poll();
}
System.out.println(sum);
sc.close();
}
}
class Problem {
int deadLine;
int cupRamen;
public Problem(int deadLine, int cupRamen){
this.deadLine = deadLine;
this.cupRamen = cupRamen;
}
}