From a816bce277b60770fd40c84628c950e94e064580 Mon Sep 17 00:00:00 2001 From: wwan13 Date: Fri, 17 May 2024 13:37:52 +0900 Subject: [PATCH] =?UTF-8?q?solve=20:=202109=20=EC=88=9C=ED=9A=8C=EA=B0=95?= =?UTF-8?q?=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/boj_2109.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 python/boj_2109.py diff --git a/python/boj_2109.py b/python/boj_2109.py new file mode 100644 index 0000000..8d6e675 --- /dev/null +++ b/python/boj_2109.py @@ -0,0 +1,32 @@ +import sys +import heapq + +input = sys.stdin.readline + + +def solution(n, data): + data.sort(key=lambda x: x[1]) + + queue = list() + for e in data: + reward, date = e + heapq.heappush(queue, reward) + + if len(queue) > date: + heapq.heappop(queue) + + return sum(queue) + + +def display_result(answer): + print(answer) + + +def main(): + n = int(input()) + data = [list(map(int, input().split())) for _ in range(n)] + answer = solution(n, data) + display_result(answer) + + +main() \ No newline at end of file