diff --git a/code_study/Baekjoon/java/_1202.java b/code_study/Baekjoon/java/_1202.java new file mode 100644 index 0000000..1e0847f --- /dev/null +++ b/code_study/Baekjoon/java/_1202.java @@ -0,0 +1,44 @@ +import java.util.*; + +class Jewel implements Comparable { + int weight, cost; + + public Jewel(int weight, int cost) { + this.weight = weight; + this.cost = cost; + } + + @Override + public int compareTo(Jewel o) { + return Integer.compare(o.cost, this.cost); + } +} + +public class _1202 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int N = sc.nextInt(); + int K = sc.nextInt(); + + ArrayList jewels = new ArrayList<>(); + for(int i=0; i Integer.compare(a.weight, b.weight)); + + int[] bags = new int[K]; + for(int i=0; i pq = new PriorityQueue<>(); + + for (int m : bags) { + while(idx < N && m >= jewels.get(idx).weight) pq.add(jewels.get(idx++)); + if(!pq.isEmpty()) ans += pq.poll().cost; + } + + System.out.println(ans); + } +}