목록heappush (2)
나의 개발일지
문제 : https://www.acmicpc.net/problem/11000 그리디, 정렬, 우선 순위 큐 import sys from heapq import heappush, heappop input = sys.stdin.readline n = int(input()) lst = [list(map(int, input().split())) for _ in range(n)] # s에 시작 t에 끝나는 수업 [s, t] lst.sort() # 수업 시작 시간으로 정렬 room = [] heappush(room, lst[0][1]) # 첫 강의 끝 시간 for i in range(1, n): if lst[i][0] < room[0]: # 다음 수업 시작 시간이 현재 수업 종료 시간보다 작으면 (강의 중이면) h..
문제 : https://school.programmers.co.kr/learn/courses/30/lessons/42626 heapq 모듈 사용 heapq는 이진 트리 기반의 최소 힙 자료구조를 제공 최소 힙으로 항상 오름차순 정렬되어 있다. 정렬된 상태를 유지해야 할 때 계속 정렬할 필요가 없어 속도가 빠르다. heapity() : 리스트를 heap으로 변환, O(N) heappush() : heap에 원소 추가, O(log(n)) heappop() : heap에서 가장 작은(0번 인덱스) 원소 삭제, O(log(n)) from heapq import heapify, heappush, heappop def solution(scoville, K): answer = 0 heapify(scoville) # ..