import sys
import heapq
input = sys.stdin.readline
N, K = map(int,input().split())
visited = [False]*K
jewel = []
for _ in range(N):
m,v = map(int,input().split())
heapq.heappush(jewel,(m,v))
bags = []
for _ in range(K):
bags.append(int(input()))
bags.sort()
result = 0
possible_jewel = []
for bag in bags:
while jewel and jewel[0][0] <= bag:
m,v = heapq.heappop(jewel)
heapq.heappush(possible_jewel,-v)
if possible_jewel:
result -= heapq.heappop(possible_jewel)
print(result)
'알고리즘 > 백준_복기_미완료' 카테고리의 다른 글
[BOJ/백준] 1722 순열의 순서 (0) | 2021.05.02 |
---|---|
[BOJ/백준] 1405 미친 로봇 (0) | 2021.05.02 |
[BOJ/백준] 1339 단어 수학 (0) | 2021.05.02 |
[BOJ/백준] 1219 오민식의 고민 (0) | 2021.05.02 |
[BOJ/백준] 1188 음식 평론가 (0) | 2021.05.02 |