목차

과제

ps
링크acmicpc.net/…
출처BOJ
문제 번호13904
문제명과제
레벨골드 3
분류

그리디

시간복잡도O(nlogn + m)
인풋사이즈n<=1000, m<=1000
사용한 언어Python
제출기록32908KB / 72ms
최고기록60ms
해결날짜2022/04/12

풀이

코드

"""Solution code for "BOJ 13904. 과제".

- Problem link: https://www.acmicpc.net/problem/13904
- Solution link: http://www.teferi.net/ps/problems/boj/13904

Tags: [Greedy]
"""

import heapq
import sys


def main():
    N = int(sys.stdin.readline())
    homeworks = [
        [int(x) for x in sys.stdin.readline().split()] for _ in range(N)
    ]

    homeworks.sort()
    max_day = homeworks[-1][0]
    submittable_homeworks = []
    answer = 0
    for day in range(max_day, 0, -1):
        while homeworks and homeworks[-1][0] >= day:
            heapq.heappush(submittable_homeworks, -homeworks.pop()[1])
        if submittable_homeworks:
            answer += -heapq.heappop(submittable_homeworks)

    print(answer)


if __name__ == '__main__':
    main()