알고리즘 문제풀이
컵라면 [백준 1781]
wiojfe
2024. 9. 30. 18:35
https://www.acmicpc.net/problem/1781
heapq를 잘 사용해서 최대 컵라면 개수를 구해준다.
import heapq
n = int(input())
arr = []
for _ in range(n):
a, b = map(int, input().split())
arr.append((a, b))
arr.sort()
heap = []
for deadline, cups in arr:
heapq.heappush(heap, cups)
if len(heap) > deadline:
heapq.heappop(heap)
print(sum(heap))