-
11279 최대 힙코테 대비 python/백준 2023. 2. 18. 00:25
11279번: 최대 힙
첫째 줄에 연산의 개수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. 만약 x가 자연수라면 배열에 x라는 값을 넣는(추가하는) 연산이고, x가 0
www.acmicpc.net
# BOJ_S2_11279_최대 힙[2023-02-17] </br> 문제 : https://www.acmicpc.net/problem/11279 <접근법> ``` 1. 최대힙 구현 heappush(heap,-num) 2. heappush, heappop ``` ```python import heapq import sys input = sys.stdin.readline n = int(input().rstrip()) heap = [] #힙 푸쉬, 힙 팝 for _ in range(n): s= int(input().rstrip()) heapq.heappush(heap,-s) if s==0: print(-heapq.heappop(heap)) elif s==0 and len(heap)==0: print(0) ```
'코테 대비 python > 백준' 카테고리의 다른 글
1743 음식물 피하기 bfs (0) 2023.02.27 2583 영역 구하기 bfs (0) 2023.02.27 22942 데이터 체커 - 스택 (0) 2023.02.12 2504 괄호의 값 - 스택 (0) 2023.02.12 10989 수 정렬하기 정렬 잡기술 (0) 2023.02.06