반응형
https://www.acmicpc.net/problem/1202
import sys
import heapq
N, K = map(int, sys.stdin.readline().split())
MV = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
bags = [int(sys.stdin.readline()) for _ in range(K)]
bags.sort()
jewels = []
for mv in MV:
heapq.heappush(jewels, mv)
ans = 0
values = []
for bag in bags:
while jewels and bag >= jewels[0][0]:
heapq.heappush(values, -heapq.heappop(jewels)[1])
if values:
ans -= heapq.heappop(values)
elif not jewels:
break
print(ans)
반응형