백준
1. 우선순위 큐
import heapq
import sys
n, k = map(int, input().split())
jewelries = []
for _ in range(n):
weight, value = map(int, sys.stdin.readline().split())
heapq.heappush(jewelries, (weight, value))
bag = []
for _ in range(k):
capacity = int(sys.stdin.readline())
heapq.heappush(bag, capacity)
total = 0
can_put_in = []
for _ in range(k):
capacity = heapq.heappop(bag)
while jewelries and capacity >= jewelries[0][0]:
(weight, value) = heapq.heappop(jewelries)
heapq.heappush(can_put_in, -value)
if can_put_in:
total -= heapq.heappop(can_put_in)
elif not jewelries:
break
print(total)
2. C++