====== 컵라면 ====== ===== 풀이 ===== * [[ps:problems:boj:13904]]와 동일한 문제. 다만 n이 커졌기 때문에, O(n^2)으로도 통과되는 [[ps:problems:boj:13904]]과 달리 우선순위큐를 쓰는 O(nlogn) 솔루션으로만 통과된다. * 풀이는 [[ps:problems:boj:13904]] 참고. ===== 코드 ===== """Solution code for "BOJ 1781. 컵라면". - Problem link: https://www.acmicpc.net/problem/1781 - Solution link: http://www.teferi.net/ps/problems/boj/1781 Tags: [Greedy] [Priority queue] """ import heapq import sys def main(): N = int(sys.stdin.readline()) problems = [] for _ in range(N): problem = [int(x) for x in sys.stdin.readline().split()] problems.append(problem) problems.sort() heap = [] answer = 0 max_deadline = problems[-1][0] for deadline in range(max_deadline, 0, -1): while problems and problems[-1][0] >= deadline: heapq.heappush(heap, -problems.pop()[1]) if heap: answer += -heapq.heappop(heap) print(answer) if __name__ == '__main__': main() {{tag>BOJ ps:problems:boj:골드_2}}