1202 - 보석 도둑

LeeKyoungChang·2022년 5월 9일
0

Algorithm

목록 보기
109/203
post-thumbnail

📚 1202 - 보석 도둑

보석 도둑

 

이해

현재 가장 작은 무게를 수용할 수 있는 가방 이하의 모든 보석 중 가장 값이 큰 것을 뽑아내고, 이를 가방이 끝날 때까지 반복하는 것이 목표이다.

설명 잘되어 있는 곳

설명 잘되어 있는 곳2

 

소스

import sys
import heapq

read = sys.stdin.readline

n, k = map(int, read().split())

listJewelry = []
listHeight = []

for _ in range(n):
    a, b = map(int, read().split())
    listJewelry.append([a, b])

for _ in range(k):
    a = int(read())
    listHeight.append(a)


listJewelry.sort()
listHeight.sort()

result = 0
temp = []

for i in listHeight:
    while listJewelry and i >= listJewelry[0][0]:
        heapq.heappush(temp, -listJewelry[0][1])
        heapq.heappop(listJewelry)

    if temp:
        result += heapq.heappop(temp)

print(-result)

 

profile
"야, (오류 만났어?) 너두 (해결) 할 수 있어"

0개의 댓글