result는 무게와 , 가치에 대한 정보가 저장된 우선순위 큐 리스트이다.
bResult는 가방의 무게에 대한 정보가 저장된 우선순위 큐 리스트이다.
가방의 리스트를 돌면서 넣을 수 있는 모든 정보를 맥스힙으로 넣고 pop 한다.
내 생각에 핵심 코드 부분은 다음 부분인 것 같다.i = 0 answer = 0 tmp = [] for j in bResult: while i < n and result[i][0] <= j: heapq.heappush(tmp, -result[i][1]) i += 1
import heapq
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
info = []
result = []
for i in range(n):
m, v = map(int, input().split())
heapq.heappush(info, [m, v])
for i in range(len(info)):
result.append(heapq.heappop(info))
bag = []
bResult = []
for i in range(k):
x = int(input())
heapq.heappush(bag, x)
for i in range(len(bag)):
bResult.append(heapq.heappop(bag))
i = 0
answer = 0
tmp = []
for j in bResult:
while i < n and result[i][0] <= j:
heapq.heappush(tmp, -result[i][1])
i += 1
if tmp:
answer += heapq.heappop(tmp)
print(tmp)
print(-answer)
# 고정 수 두는 것이 중요하다는 것 항상 잊지말자!