diff --git a/pu2rile/.DS_Store b/pu2rile/.DS_Store index b798810..66ea887 100644 Binary files a/pu2rile/.DS_Store and b/pu2rile/.DS_Store differ diff --git a/pu2rile/README.md b/pu2rile/README.md index 7d06827..fec575c 100644 --- a/pu2rile/README.md +++ b/pu2rile/README.md @@ -11,4 +11,5 @@ | 7차시 | 2024.05.10 | 완전 탐색 알고리즘 | [영화감독 숌](https://www.acmicpc.net/problem/1436) | [#26](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/25#issue-2289086909) | 8차시 | 2024.05.14 | 그리디 알고리즘 | [팔](https://www.acmicpc.net/problem/1105) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/28#issue-2295901384) | 9차시 | 2024.05.27 | 구현 | [오늘도 졌다](https://www.acmicpc.net/problem/14582) | [#29](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/29#issue-2320060288) -| 10차시 | 2024.07.11 | 스택 | [화학식량](https://www.acmicpc.net/problem/2257) | [#35](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/35#issue-2403173169) \ No newline at end of file +| 10차시 | 2024.07.11 | 스택 | [화학식량](https://www.acmicpc.net/problem/2257) | [#35](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/35#issue-2403173169) +| 11차시 | 2024.07.13 | 우선순위 큐 | [강의실](https://www.acmicpc.net/problem/1374) | [#37](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/37#issue-2406937336) diff --git "a/pu2rile/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/\352\260\225\354\235\230\354\213\244.py" "b/pu2rile/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/\352\260\225\354\235\230\354\213\244.py" new file mode 100644 index 0000000..c3c54cd --- /dev/null +++ "b/pu2rile/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/\352\260\225\354\235\230\354\213\244.py" @@ -0,0 +1,25 @@ +import heapq +import sys + +n = int(sys.stdin.readline()) + +heap = [] # 모든 강의의 시작 시간과 종료 시간을 저장할 최소 힙 +q = [] # 현재 사용 중인 강의실의 종료 시간을 저장할 최소 힙 + +# 주어진 강의 수만큼 반복하면서 강의 정보를 입력받아 최소 힙에 저장 +for _ in range(n): + num, start, end = map(int, sys.stdin.readline().split()) + heapq.heappush(heap, [start, end, num]) + +# 첫 번째 강의를 최소 힙에서 꺼내서 해당 강의의 종료 시간을 다른 힙에 저장 +start, end, num = heapq.heappop(heap) +heapq.heappush(q, end) + +while heap: + start, end, num = heapq.heappop(heap) + # 가장 빨리 끝나는 강의실의 종료 시간이 현재 강의의 시작 시간보다 작거나 같으면 종료 시간을 최소 힙에서 제거 + if q[0] <= start: + heapq.heappop(q) + heapq.heappush(q, end) # 현재 강의의 종료 시간을 최소 힙에 추가 + +print(len(q)) # 최소 힙 q의 크기가 필요한 강의실의 수