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()